[R] Program output to file using a batch command file

Jean-Victor Côté jean-v.cote at sympatico.ca
Mon Dec 31 20:37:28 CET 2007


If I copy the following commands in my batch file to the R console, R 
creates a file named "basicStatsIBM.lis" with the program output in it:

Sortie <- file(description = "basicStatsIBM.lis", open = "wt", blocking = 
TRUE,
     encoding = "UTF-8")
sink(file = Sortie, append = FALSE, type = "output", split = FALSE)
basicStats(ibm)
close(Sortie)

However, the same commands in a text file (named batch.txt, for instance) 
referred to from the R console by the command source("batch.txt") yields an 
empty "basicStatsIBM.lis" file.

Why the discrepancy in processing?
How to make the batch commands work as if the commands were pasted directly 
in the R console?
A solution to this problem would save time and aggravation to many people.  
Thank you.



More information about the R-help mailing list