7 ways to run R code

2026-03-31

There are a variety of ways to run R code:

  1. Type code at the R prompt

  2. Send code to the R prompt from a source editor, for example in RStudio

  3. Rscript to run an R script (or code) from the command line

  4. R CMD BATCH to run an R script from the command line when you’re feeling retro

  5. source() to run an R script from another R script or the R prompt

  6. RStudio background jobs to run an R script in the background

  7. callr package to run R code in a separate process