Skip to main content

a note on long running rstudio jobs

Problem: 

I have to run very time intensive code overnight, but I get kicked out of the RStudio server after 60 minutes of inactivity and the code stops running. It seems others on our team have been running into the same problem.

One solution:

One solution to this problem when using r-studio is to use the screen program, which would allow you to run a process in the background.  Some details on screen are here in our documentation: https://bookstack.grit.ucsb.edu/books/hpc-usage/page/the-screen-program

Here's how it can be used for long running jobs in r-studio:

1) You'll notice in rstudio that there is a 'terminal' option near the Console tab. If you click on this you'll have a terminal window on the server (command line interface or CLI it's called). You can then run screen like this:

screen -S 'session-name'

where 'session-name' can be any name you give the screen session. This will cause a screen session to start running, which looks like a new command prompt, but this has the feature that you can detach from it. Now you can start R at the command prompt by typing 'R' with no quotes, and R will start in your home directory just like the R session running in the Console.

Now start your long running job, then detach from the screen session by typing 'ctrl-a' at the same time, then hit  the d key - this should bring you back to the terminal prompt. If it does you can close rstudio.

Some time later you can restart rstudio, go to the terminal tab and reconnect to the screen session:

screen -r 'session-name'

Here's one line of R code that can be used to test this:

Sys.sleep(60); print("Done")

Let use know if you have any questions at help@grit.ucsb.edu.