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
- Write or paste an R script.
- Put input your script reads with readline() or readLines("stdin") in the stdin box.
- Click Run. The first run downloads R (about 15 MB); later runs start immediately.
- 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.
| Task | With a package | Base R (works here) |
|---|---|---|
| Keep matching rows | filter(df, mpg > 25) | subset(df, mpg > 25) |
| Keep some columns | select(df, mpg, cyl) | df[, c("mpg", "cyl")] |
| Add a column | mutate(df, kpl = mpg * 0.425) | transform(df, kpl = mpg * 0.425) |
| Sort rows | arrange(df, desc(mpg)) | df[order(-df$mpg), ] |
| Grouped mean | df |> group_by(cyl) |> summarise(avg = mean(mpg)) | aggregate(mpg ~ cyl, data = df, FUN = mean) |
| Count by group | count(df, cyl) | table(df$cyl) |
| Left join | left_join(a, b, by = "id") | merge(a, b, by = "id", all.x = TRUE) |
| Match text | str_detect(x, "a") | grepl("a", x) |
| Replace text | str_replace_all(x, "a", "b") | gsub("a", "b", x) |
| Read CSV data | read_csv("data.csv") | read.csv(text = "x,y\n1,2") |
Set df <- mtcars first to try each line on a built-in dataset.
Example
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.25171Each 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
- CSV to JSON: turn CSV data into JSON for other tools.
- Python Compiler: compare the analysis with pandas-style code in Python.
- SQL Playground: try the same aggregation as a SQL query.
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
Related tools
JavaScript Compiler
Run JavaScript online in an isolated browser sandbox. See console output, errors and execution time instantly, with top-level await and stdin input.
Runs in your browserTypeScript Compiler
Compile and run TypeScript online. Your code is type-checked with the official compiler in strict mode, then runs in a sandboxed worker in your browser.
Runs in your browserPython Compiler
Run Python 3 code online with the full standard library and stdin input. It runs in your browser with Pyodide (WebAssembly), so your code stays on your device.
Runs in your browserPHP Compiler
Run PHP 8.4 code online and see the output instantly, with stdin input and mbstring. PHP runs in your browser with WebAssembly, so your code stays private.
Runs in your browserC Compiler
Compile and run C code online with Clang 21, a GCC-compatible compiler: pick C89 (ANSI C), C99, C11, C17 or C23 and add stdin input. Your code stays private.
Runs in your browserC++ Compiler
Run C++ code online for free: compile C++20 with Clang 21 and libc++, type stdin input and see the output. It runs in your browser, so your code stays private.
Runs in your browser