See this page for how to start RStudio Server on BioHPC.
When you use RStudio Server to process large data matrix, RStudio loads the data matrix into the computer's memory space. If RStudio detects 2 hours of inactivity, it would free the memory space by saving your current r-session data into the hard drive. Next time you login to the RStudio web site, it would automatically reload the cached r-session data file into the memory space. The "reloading" step could take a very long time if you are working with large data objects.
If your server has sufficient memory, you can prevent RStudio from caching your r-session data onto the hard drive. This way, even if you close the RStudio web page, RStudio will keep the r-session data in memory. Next time, you can login to RStudio without delay. However, if the server is shared by several people, this practice may consume excessive memory.
To prevent hard drive caching, you can start RStudio with "noswap" as the last parameter. For example
#start RStudio with default R version 4.2.1
/programs/rstudio_server/rstudio_start noswap
#start RStudio with a different R-version
xxxxxxxxxx
/programs/rstudio_server/rstudio_start 4.2.1-r9 noswap
Move the RStudio cache directory to /workdir. By default, RStudio caches your r-session data under your home directory ("/home/$USER/.local/share/rstudio"). In BioHPC, your home directory is on a slow network drive. Run this command to clear the current cached r-session data, and move the cache to /workdir. This will speed up the "reloading" step.
xxxxxxxxxx
/programs/rstudio_server/mv_dir
"Clear Workspace" once in a while. On the RStudio web page, clicking "Session"->"Clear Workspace", then "Tools"->"Memory"->"Free unused memory" will delete all R objects and free the memory. Make sure to save important R objects into files before you clear workspace.
To save an R object:
xxxxxxxxxx
saveRDS(myobj, "mySavedObjectFile1.RDS")
To reload an R object from file:
xxxxxxxxxx
myobj <- readRDS("mySavedObjectFile1.RDS")
To list sizes of all R objects in your workspace:
xxxxxxxxxx
myObjList<-sapply(ls(), function(x) (format(utils::object.size(x), units="Mb")))
print(data.frame(myObjList))
To delete an R object from your workspace
xxxxxxxxxx
rm(myobj)
What to do if RStudio freezes?
ssh to the Linux shell, and kill all rsessions:
xxxxxxxxxx
ps -u $USER | grep rsession #skip the kill command if no rsession is found
kill xxxxxxxxx #replace xxxxxxxxx with PID
ps -u $USER | grep rsession #to verify that all your resessions have been killed.
#If "kill" not working, try the "force kill" command "kill -9 xxxxxxxxx". If "kill -9" not working, you will need to restart the Rstudio server.
Delete your R session file
xxxxxxxxxx
/programs/rstudio_server/mv_dir