First steps in R


Marie-Hélène Burle

In this section, we take our first few steps in R: we will access the R documentation, see how to set R options, and talk about a few concepts.

Help and documentation

For some general documentation on R, you can run:


To get help on a function (e.g. sum), you can run:


Depending on your settings, this will open a documentation for sum in a pager or in your browser.

R settings

Settings are saved in a .Rprofile file. You can edit the file directly in any text editor or from within R.

List all options:


Return the value of a particular option:

[1] "text"

Set an option:

options(help_type = "html")


R can accept the equal sign (=) for assignments, but it is more idiomatic to use the assignment sign (<-) whenever you bind a name to a value and to use the equal sign everywhere else.

a <- 3

Once you have bound a name to a value, you can recall the value with that name:

a  # Note that you do not need to use a print() function in R
[1] 3

You can remove an object from the environment by deleting its name:


Let’s confirm that a doesn’t exist anymore in the environment:

Error in eval(expr, envir, enclos): object 'a' not found

The garbage collector will take care of deleting the object itself from memory.


Anything to the left of # is a comment and is ignored by R:

# This is an inline comment

a <- 3  # This is also a comment