I want to write a .tsv file and use the tab separator, sep = "\t", but it seems it does not work. For example, I have this simple data
a<-c(5,1,0,3,2,0.6,1.6,7,9,0)
b<-c(11,0,1,18,11,11,0,13,20,10)
c<-c(10,20,0.7,0.8,0.3,0.4,0,0.9,1,1)
MAT<-cbind(a,b,c)
MAT<- as.data.frame(MAT)
Then I write this data into a .tsv file using
write.csv(MAT, "test.tsv", row.names = FALSE, quote = FALSE, sep = "\t")
However, when I tried to read test.tsv using
read.csv("test.tsv")
The result seems okay. But when I checked deeper using a command
more test.tsv
via the terminal, it shows that the separator is a "," instead of a tab. Could please anyone explain why it happened? And how to make the tab separator sep = "\t" works instead of ","? Thank you
CodePudding user response:
You can use function write_tsv()
from package readr
(csv is for coma separated, tsv is for tab separated)