Skip to content
Devtoolry

R Compiler

Run R code online with R 4.6, data frames, the stats package and datasets like mtcars. webR runs it in your browser, so your code and data stay private.

Something not working, or missing a feature? Send feedback

About the R Compiler

The online R Compiler runs R 4.6 in your browser with webR, so you can test a function, summarise a data frame or fit a quick linear model without installing R or RStudio. The base packages and built-in datasets such as mtcars and iris are included, and your code and data never leave your device.

Your code runs in an isolated Web Worker in your browser, so it never leaves your device.

How to use the R Compiler

  1. Write or paste an R script.
  2. Put input your script reads with readline() or readLines("stdin") in the stdin box.
  3. Click Run. The first run downloads R (about 15 MB); later runs start immediately.
  4. Read the printed values; warnings and errors appear where they happen, as in Rscript.

Example

Fit a linear model to a built-in dataset

Input

model <- lm(mpg ~ wt, data = mtcars)
round(coef(model), 3)
predict(model, data.frame(wt = 3))

Result

(Intercept)          wt
     37.285      -5.344
       1
21.25171

Each top-level value is printed, as in Rscript. Fuel economy drops by about 5.3 miles per gallon per 1,000 lb, and a 3,000 lb car is predicted to do 21.3 mpg.

Common mistakes

  • Values print only at the top level. A bare expression prints when it is a line of the script, but not inside a for loop, an if block or a function. Wrap it in print() or use cat() there.
  • readline() on your own computer. Here readline() reads a line from the stdin box, but Rscript on your computer returns an empty string because it is not interactive. For scripts that should work in both places, read input with readLines("stdin").
  • Indexing starts at 1. x[1] is the first element and x[0] silently returns an empty vector instead of an error, a common source of empty results when porting code from Python or C.

Works well with the R Compiler

Frequently asked questions

Which packages are available?

The base R packages: base, stats, utils, methods, graphics, grDevices, datasets, splines, stats4, grid, tools and parallel. CRAN packages such as dplyr or ggplot2 cannot be installed in this sandbox.

Are plots shown?

No. Plot functions run without errors, but the output panel shows text only. Use print(), summary() and table() to inspect results.

Is my code sent to a server?

No. R runs in your browser as WebAssembly (webR), so the code, its input and any data you paste stay on your device.

Can I use it instead of RStudio?

For quick scripts, exercises and checking a function, yes. For plots, CRAN packages and projects with data files, use R or RStudio on your computer.