Write lines of text to a file in R

amarillion picture amarillion · Mar 18, 2010 · Viewed 341.7k times · Source

In the R scripting language, how do I write lines of text, e.g. the following two lines

Hello
World

to a file named "output.txt"?

Answer

Mark picture Mark · Mar 18, 2010
fileConn<-file("output.txt")
writeLines(c("Hello","World"), fileConn)
close(fileConn)