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"?
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"?
fileConn<-file("output.txt")
writeLines(c("Hello","World"), fileConn)
close(fileConn)
Actually you can do it with sink()
:
> sink("outfile.txt")
> cat("hello")
> cat("\n")
> cat("world")
> sink()
hence do:
> file.show("outfile.txt")
hello
world