You can use cat to add lines to the file. The following code will write the vector as a string to a file:
myVector <- c("a","b","c") cat(myVector, file="myfile.csv", append = TRUE, sep = ",", eol = "\n")
This will create a file separated by commas, but with commas in each line, therefore it is not a CSV file.
If you need a real CSV file , use the solution given by @vamosrafa. The code is as follows:
write.table(rbind(myVector), file = "myfile.csv", row.names =FALSE, col.names = FALSE,sep = ",", append = TRUE)
The output will be like this:
"a","b","c"
If a function is called multiple times, it adds lines to the file.
source share