Introduction
R is a language built specifically for statistics and data analysis, created by statisticians for other statisticians — that focus shows up everywhere, from how naturally it handles a column of numbers to the fact that its name is a play on its predecessor, S.
Running a script
An R file is saved with a .R extension and run from a terminal with Rscript, or line by line inside an interactive session like the R console or RStudio. Either way, print() writes a value out:
print("Hello, R!")
[1] "Hello, R!"
That [1] in front of the output isn't part of your string — it's R telling you this is the first element of whatever got printed. You'll see it constantly, and it matters a lot more once you start printing longer vectors, covered in the Vectors lesson.
Assignment is silent, bare expressions aren't
Assigning a value produces no output, but typing a bare expression — even in a script run with Rscript, not just interactively — automatically prints its result:
x <- 5 x y <- 10 x + y
[1] 5 [1] 15
x <- 5 and y <- 10 produce nothing on their own. x alone and x + y alone are both bare expressions, so R prints whatever they evaluate to. This auto-printing rule is why so many R examples you'll see online never bother calling print() explicitly.
<- and = for assignment, but they're not quite interchangeable — <- is the idiomatic choice for assigning to a variable, while = is reserved by convention for naming arguments inside a function call. Sticking to <- for assignment avoids ambiguity later.