tags:

views:

67

answers:

3

I'm porting an application written in R that currently runs under Windows over to Linux (Fedora 12) and am having some problems. Currently, under Windows I invoke R to run as a batch process as:

Rterm.exe --no-save --no-restore --quiet < myRprog.r > myRprog.log 2>&1

This little batch gem executes the program myRprog.r and outputs the processed statements and errors/warnings to myRprog.log and the the executed results into myRprog.lst.

I would like to recreate the same behavior under Linux. I've tried many different variations of the following without success.

R CMD BATCH myRprog.r myRprog.lst myRprog.log

Is there a way to emulate the behavior of writing two files out (log and listing) under Linux using batch?

Thanks.

Phil Rack

+1  A: 

Try

R --no-save --no-restore --quiet < myRprog.r > myRprog.log 2>&1

there are dozens of other methods (which probably will soon appear), but this is most similar to your Windows use.

mbq
That is close but it only writes the output into myRprog.log and doesn't create a listing file.
PhilR
What do you mean? On my system it works as expected.
mbq
Right right, I have misunderstood your question. Ok, now it should work.
mbq
PhilR
Damn! I wrote that last comment to quickly. It doesn't work. I get a "file name is missing" msg in the log file. Sorry!
PhilR
It works on my machine, so I don't understand. Have you changed Rscript to R?
mbq
PhilR
Right, use R instead of Rscript.
mbq
When I do use R instead of Rscript, only testr.log is created and it contains everything from R. What platform are you using for your tests?
PhilR
I ended up solving the issue. I do a sink("testr.lst") command at the beginning and then use your command line. This works fine for me! I really appreciate your help and patience dealing with this. Linux is fairly new to me and your help has been invaluable.
PhilR
I'm glad it worked.
mbq
A: 

Or, as you're on Linux, use r from littler.

Dirk Eddelbuettel
A: 

log and lst seem to be very SASish concepts.

R CMD BATCH myRprog.r myProg.rout

will run your program and redirect all output to myProg.rout. However, you are free to modify myProg.r so that datasets and the like are written into different files that you can then capture (possibly from an external application).

datanalytics.com
It is pretty SAS like. What I'm doing is passing parms from a WPS program (a SAS language alternative) to R for execution of some statistical programs. I invoke R and wait for it to complete and then read in the log/listing into the appropriate files.
PhilR