Advertisement

Online R Compiler

Write, run and test R code online, right in your browser. This free online R compiler needs no installation or signup — just type your code and click Run.

R is a language for statistics, data analysis and visualisation, widely used by data scientists, researchers and analysts.

How to use the R compiler

  1. Write or paste your R code in the editor.
  2. If your program reads input, open the I/O tab and type it into the STDIN box (one value per line).
  3. Click Run — the output and any errors appear in the output panel.

Sample: read input in R

con <- file("stdin")
name <- readLines(con, n = 1)
close(con)
cat("Hello,", name, "\n")

Paste this into the editor, type your name in the STDIN box and click Run.

More R examples to try

Vectors and summary statistics

R is built for statistics — summarise a vector in one line.

marks <- c(78, 91, 64, 85, 72, 99)
print(summary(marks))
cat("Standard deviation:", sd(marks), "\n")
cat("Above 80:", marks[marks > 80], "\n")

Data frames

A data frame is R's table type, like a spreadsheet in code.

students <- data.frame(
  name  = c("Asha", "Ravi", "Meena", "John"),
  marks = c(91, 64, 85, 72),
  city  = c("Chennai", "Delhi", "Chennai", "Pune")
)
print(students[students$marks > 70, ])
print(aggregate(marks ~ city, data = students, FUN = mean))

Common R errors and how to fix them

Error: object 'x' not found
The variable does not exist — check spelling (R is case-sensitive) and that the line creating it ran first.
Error in library(x): there is no package called
That package is not installed on the online compiler. Use base R functions, which cover most beginner tasks.
non-numeric argument to binary operator
You did maths on text. Convert with as.numeric(), especially for values read from input.
readline() returns an empty string
readline() only works in interactive R. Read STDIN with readLines("stdin") as in the sample above.

Frequently asked questions

Is this online R compiler free?

Yes. It is completely free to use, with no signup required to write and run code.

Do I need to install anything?

No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.

How do I give input to my R program?

Before clicking Run, type the input into the STDIN box under the I/O tab, one value per line. Your program reads it as standard input, just like typing in a terminal.

Is this good for learning R?

Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.

Other online compilers

Editor powered by OneCompiler.