If you want to execute your entire buffer - if you are running Unix / Linux, you can also run your script with shebang:
And make your executable
chmod 744 myscript.r
(I remember that Google loves their r-scripts to end in .R, but ok ...) and you can execute it like this:
./myscript.r
And, with arguments,
./myscript.r arg1 arg2
(which I actually used to call the R function from the Matlab system call), and in your R file, you can use
userargs = tail(commandArgs(),2)
to get arg1 and arg2. You can also do without shebang:
R --no-save < myscript.r arg1 arg2
etc. With Windows, I remember that it was
R CMD BATCH myscript.r
or something like that ... I noticed a slight delay when running commands through ESS (although I really love ESS), so when I know that I want to run the entire buffer, I sometimes run the shell in the window below the R script (where usually there will be a buffer R) and use the tricks above.
You can also use
echo 'source("myscript.r")' | R --no-save
- The advantage of using these methods when running 'source ("myscript.r")' directly in R or the R buffer is that you start with a clear work area (although you have to be careful that your. Rprofile will not load if you will not name the "source (" ~ / .Rscript ") explicitly in" myscript.r "), so you can be sure that your script is autonomous (it calls the appropriate libraries, lexically -scoped do not refer to unintended variables in global space that you forgot to delete, etc.).
source share