Your First R Program
An R script has no compile step and no required entry-point function — no main, no class wrapper. The interpreter runs top-level statements in order, the moment the file executes. print() shows a value the way R would show it if you typed it directly at a prompt — including a [1] index prefix and quotes around strings. cat() writes values concatenated together with no quotes and no index prefix, and adds no trailing newline for you unless you include \n yourself. Comments start with # and run to the end of the line.
Run it yourself
This was actually executed to get the output shown below — try changing the text and running it yourself using the button under the example.
# This is a comment
print("Hello, R!")
cat("No newline here")
cat(" - still same line\n")
[1] "Hello, R!" No newline here - still same line
Notice print() wrapped "Hello, R!" in quotes and prefixed it with [1] (R's way of marking "this is element 1 of the vector you're looking at") — print() always shows you a value's structure, not just its contents. The two cat() calls, by contrast, landed on the same output line with no quotes at all, because cat() never adds a newline on its own and never shows you anything beyond the raw text. Next: vectors and assignment — <- assignment, c(), and what "everything is a vector" actually looks like in practice.
Practice exercise
Add a comment above your code, then print "Learning R one step at a time."