Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing to file using cat and write in r

Tags:

r

I'm trying to write the output of cat into a file in R like this:

write(cat(as.character(i),"\n"),file="output.txt",append=TRUE)

However, it is not writing anything.

Note- cat(as.character(i),"\n" has a non-null output.

What am I missing or doing wrong here?

like image 905
HackCode Avatar asked Oct 24 '25 02:10

HackCode


1 Answers

Why are you using cat inside write?

write is a wrapper for cat, so you could use either write or cat for this, but not both:

write(as.character(i), file = "output.txt", append = TRUE)

or

cat(as.character(i), sep = "\n", file = "output.txt", append = TRUE)
like image 55
Jon Calder Avatar answered Oct 26 '25 17:10

Jon Calder