2026-03-31
There are a variety of ways to run R code:
Send code to the R prompt from a source editor, for example in RStudio
Rscript to run an R script (or code) from the command line
R CMD BATCH to run an R script from the command line when you’re feeling retro
source()
to run an R script from another R script or the R prompt
RStudio background jobs to run an R script in the background
Render an R markdown or quarto document
callr package to run R code in a separate process
targets package to run a pipeline
rig to run code with different versions of R
webr to run R code in your browser
rpy to run R code from python
Updated 2026-04-02 with thanks to Ken Butler, Urs Wilke, Jordi Rosell and EpicBear for their suggestions.