How to use the online R compiler
- Write or paste an R script into the editor. Reset example restores the starter script, which summarises a vector, fits a linear model and draws a plot.
- Press Run or use Ctrl + Enter (⌘ + Enter on a Mac). The whole script runs from top to bottom.
- Read the results in the Output panel. Text appears just as it would in the R console, and any plots you draw are shown below it as images.
- Choose a time limit of 5, 15 or 60 seconds. A script that runs longer is stopped, and Stop interrupts it at any time.
The first run downloads R itself, about 25 MB, so allow a few seconds. Later visits load it from your browser cache. Save your work with Copy or the main.R download, adjust the font with A− and A+, switch between side-by-side and stacked panes with the layout button, or press Full screen (Ctrl/⌘ + Shift + F, Esc to exit) when you need space for a long script and its plots.
R runs entirely in your browser. Your script and data are not sent to any server, and the editor stores your last script only in your browser's local storage.
What's supported
The page runs R 4.6.0 through webR 0.6, the official WebAssembly build of R. It is the real R interpreter, so functions, vectors, factors, lists and data frames behave as they do in RStudio or the R console.
- Console-style output: a value on its own line is auto-printed, exactly as when you type it at the
>prompt.print(),cat()andmessage()also work. - Errors and warnings from
stop(),warning()and R itself are shown in the output. - Base graphics:
plot(),hist(),barplot(),boxplot(),lines(),abline(),legend()and friends. Each plot appears in the output panel as a 720×450 image. - Base R and the recommended packages that ship with webR, including the
statsfunctions (lm(),t.test(),cor(),quantile()) and the built-in datasets such asmtcarsandiris.
Limitations:
install.packages()is not supported on this page, so packages from CRAN, such as ggplot2 or dplyr, are not available. Stick to base R.- No interactive input.
readline()andscan()from the keyboard cannot be used, so define your data in the script. - No access to files on your computer. Use
read.csv(text = "...")to load a small CSV pasted into the script.
A short R walkthrough
# Vectors are the basic unit, and operations work element by element
x <- c(4, 8, 15, 16, 23, 42)
x * 2
mean(x); median(x)
x[x > 10] # logical indexing
# Data frames hold tables
df <- data.frame(
hours = c(1, 2, 3, 4, 5, 6),
score = c(52, 58, 65, 70, 74, 83)
)
str(df)
# Fit a linear model and inspect it
fit <- lm(score ~ hours, data = df)
summary(fit)
predict(fit, newdata = data.frame(hours = 7))
# Plot the data and the fitted line
plot(df$hours, df$score, pch = 19, xlab = "Hours studied", ylab = "Score")
abline(fit, col = "red", lwd = 2)
summary(fit) prints the coefficients, their standard errors and p-values, and the R-squared. The abline(fit) call draws the regression line on top of the scatter plot, and the image appears right after the text output.
Tips and common pitfalls
- R indexes from 1, and
x[0]silently returns an empty vector rather than an error. - Inside a loop or a function, values are not auto-printed. Wrap them in
print(). - Use
<-for assignment and==for comparison.=also assigns at the top level, but mixing the two styles makes scripts harder to read. - Missing values propagate:
mean(c(1, NA, 3))isNA. Passna.rm = TRUEto ignore them. - Functions that use random numbers, like
rnorm()andsample(), give different results each run. Callset.seed(42)first for repeatable output.
par(mfrow = c(1, 2)) before the plotting commands.Frequently asked questions
Which version of R is this?
R 4.6.0, running on webR 0.6. Run R.version.string to confirm.
Can I use ggplot2, dplyr or the tidyverse?
No. Installing packages is not supported on this page. Base R covers data frames, aggregation (aggregate(), tapply()), modelling and plotting, which is enough for most exercises.
Where do my plots appear?
In the output panel, after the text output, as 720×450 images. Each new high-level call such as plot() or hist() starts a new image.
Can I run other data languages here?
Try the online Python compiler for NumPy and pandas, or the online SQL compiler for queries. All the options are listed under online compilers.