Reputation: 631
I'm trying to write a txt file that has multiple delimiters:
text|||value_1|value_2||||
Currently, I've tried:
write.table(variable, "file.txt", sep = "|", quote = FALSE, row.names = FALSE)
But I'm not sure how to use multiple delimiters given that sep only takes in 1 argument. Will appreciate any help! Thank you!
Upvotes: 0
Views: 204
Reputation: 32558
Maybe you can write using one delimiter, read it back, and replace the one delimiter with whatever you want before writing again
write.table(mtcars, "tmp.txt", sep = "|", quote = FALSE)
d = readLines("tmp.txt")
d = gsub("|", "|||", d, fixed = TRUE)
writeLines(d, "tmp2.txt")
Upvotes: 1