Hello, World

The smallest R script, and the difference between print(), cat() and a value on its own line.

Runs in Zerethon IDE · R 4.5 Official R documentation ↗

An R script runs from top to bottom. print() shows a value the way the R console does, with [1] before it; cat() writes plain text and adds no newline unless you include \n.

main.R
print("Hello, World!")
cat("Sum: ", 2 + 3, "\n", sep = "")
cat("a", "b", sep = "-")
cat("!\n")
x <- c(1, 2, 3)
x

Output

[1] "Hello, World!"
Sum: 5
a-b!
[1] 1 2 3
  • A value alone on a line (x) is printed, as in the console.
  • [1] is the position of the first element shown on that line — R treats every value as a vector.
  • <- is the usual way to assign; = also works. A line starting with # is a comment.

Related topics

Official references