Running R in batch mode on Linux: release issues

I run the R program in a linux cluster because it is very demanding on my processor. My program is designed to output several (about 15) charts in PDF format to the folder from which the program collects its data.

I want my program to run in the background and continue to work when I exit the cluster.

First, I tried this:

cd /Users/The/Folder/With/My/RScript #changed working directory nohup ./BatchProgram.R & 

However, this did not work because it added the output to a file named nohup.out and did not output any of the PDF files that I needed.

Next I tried this:

 cd /Users/The/Folder/With/My/RScript #changed working directory R #to run R source('BatchProgram.R') #to run my program 

This gave me the desired result, but did not run the program in the background (and will stop when I exit the cluster).

Can someone enlighten me on how I can get the output of my second block of code while the program is running in the background and make it continue to work even after leaving the Linux cluster (for example, the first block of code)?

Many thanks!

+4
source share
2 answers

nohup runs the command in the background, makes it ignore signals telling it to stop (for example, when it logs out), and redirects the output to a file. But it should be an executable command: you probably have error messages in nohup.out telling you that BatchProgram.R could not be started.

The following should work:

 nohup Rscript ./BatchProgram.R & 
+9
source

The solution is checked, you can also try to make it "nohup", but what will be presented suits me. Make a bash script as follows (e.g. run_R.sh):

 #!/bin/sh R CMD BATCH --slave ./_your_R_script_name.R & exit 0 

then make it runnable

 chmod +x run_R.sh 

and run the file for example

 ./run_R.sh 

sometimes you can only get a blinking cursor (depending on which linux distribution you are running), but just press enter to continue

+3
source

All Articles