简体   繁体   中英

Trouble with extra character while using 'write.table'

I am using R 3.3.4 and RStudio 1.1.453. I am creating lines of data passed from a function call, then using write.table() to write one line (and only one line) of data into one file at a time to obtain a .tsv.

I know it's a noobie question but so am i. :)

for (i in 1:n) {
write.table(make_line(),
            file = (paste("file", i, ".tsv", sep = "")),
            quote = FALSE,
            eol = "\r\n",
            sep = '\t'
            )
}

However my output is:

x
1   >chr4   820383   966802   CAC   TRUE

when make_line() generates below and that is all I want:

>chr4   820383   966802   CAC   TRUE

Those are default row and column names. To avoid them, set row.names and col.names to FALSE in write.table .

write.table("AAAA")
# "x"
# "1" "AAAA"

write.table("AAAA", row.names=FALSE, col.names=FALSE)
# "AAAA"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM