[R] Opening a .R file with R (Windows)

Gabor Grothendieck ggrothendieck at gmail.com
Thu Sep 30 15:31:57 CEST 2010


On Tue, Sep 28, 2010 at 1:11 PM, Kye Gilder <kye.gilder at gmail.com> wrote:
> I am new to using R.  I installed R on my computer (Windows) and everything
> things appears to be just fine.  However, I have a simple script RTest.R
> that does a few simple calculations.  When I double-click the RTest.R icon,
> I get an Information dialong box which says, "ARGUMENT 'C:\Documents and
> Settings\kgilder\Desktop\RTest.R' __ignored__" .  When I choose OK, R then
> opens, but it does not open or display the script.  Any help or suggestions?
>
> When I open R and use File >> Open New Script and path to the file, it opens
> just fine.

There is a batch file called #Rscript.bat at
http://batchfiles.googlecode.com .  If you (1) place #Rscript.bat
anywhere on your path and then (2) place this line at the top of your
R file:

#Rscript %0 %*

and (3) rename your R file to end in .bat then it can be used as both
a bat file and as an R file.  If you double click it then it will run
the script since its a bat file yet you can also source() it into R
like any R file.    It does produce one garbage line of output at the
top so it will only be usable in situations where that is ok.   Note
that #Rscript.bat finds R from the registry so if you upgrade R you
will not need to make any changes to your scripts that use it.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list