So I have a semi-answer for myself. I don't think this way is preferable,
but if you're going through the same thing as me, maybe it'll help.
If you pass your desired outfile as an argument in '--args filename',
you can redirect the output the following way:
cmd_args = commandArgs()
print (cmd_args) #To figure out which number argument your outfile is
sink(cmd_args[2], append=TRUE) #Or whatever number argument your filename is
|
|
code
|
|
sink() #at the end of your script
Stderr I think still gets directed to your outfile location in the R CMD
BATCH... command (see start of thread), but Stdout should now go to wherever you
directed it with sink, plus, now you can append.
HTH (and if you're aware of a better way, please let me know!)
~Michael Turchin
Children's Hospital Boston
The Broad Institute
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On
Behalf Of Turchin, Michael [Michael.Turchin at childrens.harvard.edu]
Sent: Thursday, March 11, 2010 5:27 PM
To: r-help at r-project.org
Subject: [R] Append to outfile in R CMD BATCH mode
Is there a way to append to the outfile when using R CMD BATCH? My code, right
now, is:
R CMD BATCH --slave --vanilla '--args place .2 -.1 .9 .6'
StratificationSimulation example.output
Everything else is working the way I'd like it. The first few lines of code
of my script file are:
options(echo=FALSE)
cmd_args = commandArgs()
print (cmd_args)
#d <- read.table("/dev/stdin")
if that helps any. However, I cannot currently change the output to append,
rather than override, the designated outfile. Maybe I could potentially use
sink(__, append=TRUE) if I could somehow reference the outfile from within the
script (and assuming my understanding of sink() is correct)?
Any thoughts, or help? They're all greatly appreciated.
Thanks!
~Michael
Children's Hospital Boston
The Broad Institute
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.