I wish to use R CMD BATCH to run a small R function which reads a text file and plots a single graph to a PDF file.> version_ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 4.0 year 2006 month 10 day 03 svn rev 39566 language R version.string R version 2.4.0 (2006-10-03)>The text files are monthly data, (called lyrical names like October.txt or November.txt) and the end result of each run will be a PDF file called October.pdf, etc. It's simple enough to make a separate file for each month which has the command to call the R function, e.g. October.r would be plot.month("October.txt") and use it like so: R CMD BATCH October.r /dev/null (the R function creates the name for the PDF file) or slightly more elegantly, a one line shell script that takes an argument: R CMD BATCH $1.r /dev/null (so that the script name and the name of the month will make a PDF file for that month) What I'd like to do is avoid the need to make the Month.r files and have the script pass the month information directly to the function that a single .r file would call. If I brushed up on a bit of Perl, I might work out how to modify the shell script to do such a thing, but I suspect it should be simpler than that. I had thought of using litter for such a thing, but as I looked into it, I get the impression that's not the idea of litter. (I'm also a bit reluctant to recompile R.) Ideas welcome. Thanks -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Middle minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
Patrick Connolly <p_connolly <at> ihug.co.nz> writes:> What I'd like to do is avoid the need to make the Month.r files and > have the script pass the month information directly to the function > that a single .r file would call.?commandArgs
Try this: gannet% cat month.R x <- commandArgs() print(x[length(x)]) gannet% R --slave --args January < month.R [1] "January" On Thu, 23 Nov 2006, Patrick Connolly wrote:> I wish to use R CMD BATCH to run a small R function which reads a text > file and plots a single graph to a PDF file. > >> version > _ > platform x86_64-unknown-linux-gnu > arch x86_64 > os linux-gnu > system x86_64, linux-gnu > status > major 2 > minor 4.0 > year 2006 > month 10 > day 03 > svn rev 39566 > language R > version.string R version 2.4.0 (2006-10-03) >> > > The text files are monthly data, (called lyrical names like > October.txt or November.txt) and the end result of each run will be a > PDF file called October.pdf, etc. > > It's simple enough to make a separate file for each month which has > the command to call the R function, e.g. October.r would be > plot.month("October.txt") > and use it like so: > > R CMD BATCH October.r /dev/null > (the R function creates the name for the PDF file) > > or slightly more elegantly, a one line shell script that takes an argument: > R CMD BATCH $1.r /dev/null > (so that the script name and the name of the month will make a PDF > file for that month) > > What I'd like to do is avoid the need to make the Month.r files and > have the script pass the month information directly to the function > that a single .r file would call. If I brushed up on a bit of Perl, I > might work out how to modify the shell script to do such a thing, but > I suspect it should be simpler than that. > > I had thought of using litter for such a thing, but as I looked into > it, I get the impression that's not the idea of litter. (I'm also a > bit reluctant to recompile R.) > > Ideas welcome. > > > Thanks > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595