Index of /examples/r/examples/io_append

Icon  Name                    Last modified      Size  Description
[DIR] Parent Directory - [   ] prof1.out 06-Feb-2015 14:46 22 [   ] Rprof.out 06-Feb-2015 14:44 45 [   ] io_inefficient.R 15-Mar-2014 00:34 1.9K [   ] io_better.R 14-Mar-2014 23:51 1.9K

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.

Interactive execution:

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

Contact Information:

Katia Oleinik: koleinik@bu.edu

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.