R · Lesson 1 · On the house

Hello, R

Rscript, print, cat, #, <-. Lesson 1 is free — on the house.

Lessons · R · Lesson 1 of 10 · On the house

Hello, R

Rscript, print, cat, #, <-.

Illustration for R
Lesson 1 is on the house.

R is a language for statistics and data. Source files usually end in .R. From a terminal with R installed, run Rscript hello.R. Inside an interactive session you type at the > prompt; Ctrl+L or q() leave the session when you are done exploring.

print(x) shows a value with a [1] index label for atomic vectors. cat("hello\n") writes text without that label — use cat when you want clean console output. Both accept multiple arguments.

Comments start with # and run to the end of the line. There is no /* */ block comment in base R. Prefer short comments that name intent, not restatements of the code.

Assignment uses <- by house style: x <- 3. = also assigns in most places, but <- is the conventional choice in scripts and packages. Function arguments still use = (mean(x, na.rm = TRUE)).

Misses: writing print "hello" like Perl, using console.log, treating Python = as the only assignment form, or saving scripts as .py and running them with python.

hello

# hello.R
name <- "Ada"
print(name)
cat("hello\n")
Match this when you type.

Quiz

How do you run an R script from the CLI?

Quiz

Which operator is the conventional assignment form in R scripts?

Quiz

What does cat("hello\n") do compared to print?

Quiz

How do comments begin in R?

Check

Match the still for: Hello, R.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.