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"?
Based on the best answer:
Note that the
yourObject
needs to be in a string format; useas.character()
to convert if you need.But this is too much typing for every save attempt. Let's create a snippet in RStudio.
In Global Options >> Code >> Snippet, type this:
Then, during coding, type
wfile
and press Tab.The ugly system option
What's about a simple
writeLines()
?or
You could do that in a single statement
Actually you can do it with
sink()
:hence do:
I would use the
cat()
command as in this example:You can then view the results from with R with