R with HPC
1
0
Entering edit mode
3.8 years ago
storm1907 ▴ 30

Hello, I have a custom R script, that I need to run on HPC server, not in Rstudio. I am unable to run this script; How can I start R code in Linux shell?

Thank you!

R • 1.4k views
ADD COMMENT
1
Entering edit mode

Assuming your script has a proper shebang:

chmod +x yourScript.R
./yourScript.R
ADD REPLY
3
Entering edit mode
3.8 years ago

There are two preferred ways to explicitly invoke R scripts, either via R CMD BATCH (old) or Rscript (newer).

  1. Make sure that Rscript is available to you on the server, i.e. just typing Rscript should print the manual for Rscript to the screen.
 Rscript
Usage: /path/to/Rscript [--options] [-e expr [-e expr2 ...] | file] [args]

--options accepted are
  --help              Print usage and exit
  --version           Print version and exit
  --verbose           Print information on progress
  --default-packages=list
                      Where 'list' is a comma-separated set
                        of package names, or 'NULL'
or options to R, in addition to --slave --no-restore, such as
  --save              Do save workspace at the end of the session
  --no-environ        Don't read the site and user environment files
  --no-site-file      Don't read the site-wide Rprofile
  --no-init-file      Don't read the user R profile
  --restore           Do restore previously saved objects at startup
  --vanilla           Combine --no-save, --no-restore, --no-site-file
                        --no-init-file and --no-environ
  1. Rscript myScript.r --vanilla should then do the trick (or whatever other parameter for Rscript you prefer. I recommend to check that all packages your script may rely on are actually installed on the server. For this, you could open an interactive R session simply by typing $ R. This will create the same type of session that you normally have in your RStudio console (if R is installed on the server and supplied in your path. Sometimes you will have to figure out the path to where the software on the servers is installed, but that's independent of R).

PS: The solution suggested above where the script is executed via the ./myScript.R expects that the first line in that script points to Rscript or the R installation via a shebang line. You can read more details on stackoverflow, e.g. here.

ADD COMMENT

Login before adding your answer.

Traffic: 2444 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6