Skip to content
Devtoolry

Online 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.

Runs in your browser · Nothing uploadedFree · No sign-up

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. It works as an online R editor and R simulator, from a quick calculation to a full script or a simulation with set.seed(), rnorm() and sample(). 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.

Base R instead of packages

CRAN packages cannot be installed here, but base R does the common dplyr, stringr and readr jobs. Each line on the right runs in this compiler.

TaskWith a packageBase R (works here)
Keep matching rowsfilter(df, mpg > 25)subset(df, mpg > 25)
Keep some columnsselect(df, mpg, cyl)df[, c("mpg", "cyl")]
Add a columnmutate(df, kpl = mpg * 0.425)transform(df, kpl = mpg * 0.425)
Sort rowsarrange(df, desc(mpg))df[order(-df$mpg), ]
Grouped meandf |> group_by(cyl) |> summarise(avg = mean(mpg))aggregate(mpg ~ cyl, data = df, FUN = mean)
Count by groupcount(df, cyl)table(df$cyl)
Left joinleft_join(a, b, by = "id")merge(a, b, by = "id", all.x = TRUE)
Match textstr_detect(x, "a")grepl("a", x)
Replace textstr_replace_all(x, "a", "b")gsub("a", "b", x)
Read CSV dataread_csv("data.csv")read.csv(text = "x,y\n1,2")

Set df <- mtcars first to try each line on a built-in dataset.

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.

Can I use it as an R simulator?

Yes. Random number functions such as rnorm(), runif(), rbinom() and sample() work as in desktop R. Call set.seed() first so the same simulation gives the same numbers every run, and summarise the results with mean(), quantile() or table().

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.

How do I read input in R online?

Type it into the stdin box before you click Run. readline() returns the next line, and readLines(file("stdin")) returns every line as a character vector, which also works with Rscript on your own computer.

Can I install CRAN packages such as dplyr or ggplot2?

No. Only the base R packages are available, so library(dplyr) fails with "there is no package called ‘dplyr’". Base R covers most steps: subset() for filter(), aggregate() for grouped summaries, merge() for joins and order() for sorting.

Is R compiled or interpreted?

Interpreted: R reads and evaluates your script line by line, like the R console. Many functions in base R are written in C and Fortran, which is why vectorised code is fast. "R compiler" is simply the name many people search for.

Guides and tutorials