In RStudio
If you right-click on RStudio, you can open several separate "sessions" of RStudio (regardless of whether you use Projects or not). By default, they will use 1 core each.
Update (July 2018): RStudio v1.2.830-1, available as a preliminary release, supports the Jobs panel. This is about running R scripts in the background separately from an interactive R session:
Run any R-script as a background job in a pure R-session
Monitoring progress and viewing script output in real time
If you wish, provide the tasks with a global environment at startup and export the values back after completion
This will be available in RStudio version 1.2.
Running scripts in the terminal
If you have several scripts that, as you know, run without errors, I would recommend running them with various parameters through the command line:
RCMD script.R RScript script.R R --vanilla < script.R
Running in the background:
nohup Rscript script.R &
Here "&" runs the script in the background (it can be obtained with fg , tracked with htop and killed with kill <pid> or pkill rsession ), and nohup saves the output to a file and continues to work if the terminal is closed,
Passing arguments to a script:
Rscript script.R 1 2 3
This will pass c(1, 2, 3) to R as the output of commandArgs() so that a loop in bash can run multiple instances of Rscript with a bash loop:
for ii in 1 2 3 do nohup Rscript script.R $ii & done
Running parallel code in R
You will often find that a certain step in your R-script slows down the calculations, can I suggest running parallel code in your R-code rather than running them separately? I would recommend the snow package to run parallel loops in R. Usually instead of using:
cl <- makeCluster(n) # n = number of cores (I'd recommend one less than machine capacity) clusterExport(list=ls()) #export input data to all cores output_list <- parLapply(cl, input_list, function(x) ... ) stopCluster() # close cluster when complete (particularly on shared machines)
Use this wherever you usually use the lapply function in R to run in parallel.