To append data to an existing file in R, you need to open the file in "append" mode using the file()
function with the parameter open = "a"
. Then, you can use the cat()
function to write text or data to the file.
main.r218 chars9 lines
In the example above, we open the file "path/to/file.txt" in append mode and create a file connection named file_conn
. Then, we use the cat()
function to append the text "New data to append." to the file. The "\n" at the end of the string is important to add a newline character.
Finally, we close the file connection using the close()
function to save the changes to the file.
gistlibby LogSnag