Appending results to single or multiple files one line at a time
This directory contains two R scripts: io_inefficient.R script contains an example of inefficient way to save the results in 3 output files. io_better.R script provides a better approach.
When cat, write, write.table and sink are used for appending to the existing file with argument file defined as a character string, the output file is opened for writing, modified and closed again at the end of the function call. If you need to repeatedly write to the same file, it is more efficient to open a connection to the file and pass this connection to the write statement, closing the connection after the last write statement.
See Output to connection (CRAN manual) for more details.
Each script can be executed using source() funcion inside R enviroment.
They can also be executed using R or Rscript commands: scc1% R CMD BATCH io_better.R
or scc1% Rscript io_better.R
Katia Oleinik: email@example.com
Note: Research Computing Services (RCS) example programs are provided
"as is" without any warranty of any kind. The user assumes the entire risk of
quality, performance, and repair of any defects. You are encouraged to copy
and modify any of the given examples for your own use.