R playground

Run R online

Write and run R code online with base R 4.1. A free R compiler in your browser for vectors, data frames and statistics, with no install or sign-up.

Code main.R

# Welcome to the coding.kitty R playground.
# Press Run (or Ctrl+Enter) to see what this prints.

cats <- data.frame(
  name = c("Miko", "Nola", "Baymax"),
  age = c(3, 5, 1)
)

# Youngest first.
cats <- cats[order(cats$age), ]
print(cats, row.names = FALSE)

for (i in seq_len(nrow(cats))) {
  cat(sprintf("%d. %s says meow\n", i, cats$name[i]))
}

cat("Average age:", mean(cats$age), "\n")

# Type a name in the Input box and press Run again to see this line.
input <- file("stdin")
name <- readLines(input, n = 1)
close(input)
if (length(name) == 1) cat("Hello, ", name, "!\n", sep = "")
Output

Press Run to see what your code prints.

About this R playground

This is an R compiler you can use straight away. Write R in the editor, press Run, and the output appears next to it: everything your script prints, any warning or error, and how long it took.

Your code runs on R 4.1 with Rscript, in an isolated sandbox on our servers, so it behaves as it would with Rscript main.R on your own machine. It is free, with nothing to install and no account needed.

What you can run

  • R 4.1, running one file per run, saved as main.R.
  • Standard library only. Base R: vectors, lists, data frames, factors, the apply family, regular expressions, and the stats, utils and datasets packages, so mean, sd, lm, t.test, table and datasets such as mtcars and iris are all there. There is no package installer, and programs have no network access.
  • Limits: 10 seconds and 256 MB of memory per run. Output past 64 KB is cut off, code can be up to 64 KB and input up to 16 KB.
  • Fair use: 5 runs a minute and 50 a day without an account, 10 a minute when you are signed in.

Reading input

Open the Input box under the editor and type what your script should read, then read it from standard input with readLines. readline() does not read it, because a script is not an interactive session. With the box empty, readLines returns an empty vector.

input <- file("stdin")
lines <- readLines(input)
close(input)

Frequently asked questions

Is this online R compiler free?

Yes. There is no sign-up and no limit on how much you can write. Signed-out visitors get a quick, usually invisible bot check when they press Run, and a fair-use cap of 5 runs a minute and 50 a day. Signing in raises it to 10 runs a minute.

Which version of R does it run?

R 4.1 on Linux, running your script with Rscript. The native pipe (|>) and the short function syntax (\(x) x + 1) both work.

Can I install packages like dplyr or ggplot2?

No. The playground runs base R only: there is no install.packages() and no network, so CRAN packages such as the tidyverse are not available. The packages that come with R itself, stats, utils, graphics, methods and datasets, all load as normal.

Can I draw plots?

Not here. Plotting functions run without an error, but the playground shows text output only, so the plot is not displayed. Use print, cat, summary and table to see your results.

How do I read input in the R playground?

Type it in the Input box under the editor, then read it with readLines(file("stdin")), which returns one string per line. Convert numbers with as.numeric. readline() only reads from a keyboard in an interactive session: in a script it returns an empty string straight away.

Why did my script stop with a time-out?

Each run gets 10 seconds and 256 MB of memory. A program that goes past either is stopped. The usual cause is a repeat loop with no break, or a while loop whose condition never turns false.

Is my code saved or shared?

Your code is kept in your own browser so it is still there next time, and nowhere else. When you press Run it is sent to our code runner, run once in a sandbox, and thrown away. We do not store it or show it to anyone.

Keep going

Also in the playground: Python, JavaScript, TypeScript, SQL, Bash, C, C++, Go, Rust, Java, C#, Ruby, PHP, Lua, Dart, Swift.