[R] command files

Gabor Grothendieck ggrothendieck at gmail.com
Tue Dec 2 17:35:59 CET 2008


On Tue, Dec 2, 2008 at 11:18 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> 2008/12/2 b g <shakespeare_1040 at hotmail.com>:
>>
>> Since I'm a SAS programmer, I'm used to creating command files in an editor for submission later.  Is there a way to do this in R?  I'd need to retain an ouput listing and a log to check for errors.
>
>  You probably want R CMD BATCH from a command-line. For example, if myjob.R is:
>
> x=runif(100)
> y=runif(100)
> m=lm(y~x)
> summary(m)
>
>  and I do:
>
> R CMD BATCH myjob.R
>
> from a command prompt then when it finishes I get a file "myjob.Rout"
> which is a transcript file just like you'd see if you did things
> interactively.
>
>  Normally on a Unix box 'R' will be in your path so you can type it
> just like that from a terminal window. From Windows, I'm not so sure,
> so you may have to type the full path, like:
>
> C:\Program Files\R-2.8.0\bin\R.exe CMD BATCH myjob.R

On Windows if you grab Rcmd.bat from http://batchfiles.googlecode.com
and place it anywhere in your PATH then you can do the above like this:

Rcmd BATCH myjob.R

without having to set any paths.  Rcmd.bat and all other batch files
in that collection, are self contained so installation is just a matter of
placing whichever you need anywhere on your path.  Rcmd.bat finds
R by looking into the registry and then runs it.



More information about the R-help mailing list