Get help in R

Help on functions

If you know the name of the function you’re trying to use, access the help page by:

  • Typing a ? followed by the function name, or
  • Passing the function name to the help() function:
?summary
help(summary) # same result

Help page structure

The help page is divided into sections. This format is fairly consistent between different pages and can make it easier to find what you need

  1. Name of the help topic in large font
  2. Description - the purpose of the function(s)
  3. Usage and Arguments - parameters that must be supplied to the function for it to work correctly, plus their default values
  4. Examples of how to use that function - these can be really useful to understand the structure of functions, and how to format the arguments

If you don’t know the name of the function for what you’re trying to do, you can:

  1. Search the help for mentions of specific words using help.search()
  2. Precede the word with double question marks ??
help.search("categorical")
??categorical # same result

More on help.search()

Tip

#| echo: true # Use quotes for topic searches Enclose your search term in double quotes so that R knows it’s a character string (i.e. a normal word or phrase) NOT a function or object name

If you want to search for a multi-word phrase, you must use help.search() instead of ??:

help.search("bar chart")

Use function help.start() to open a help browser page. From the page you can access manuals including “An Introduction to R” by the R core development team, references and other material:

help.start()

Limit your search by package

Sometimes the same name is used by diverse functions in different packages

When searching for help on a particular function, you can restrict your search to the relevant package by typing the name of the package followed by :: and then the function name

For example, compare a search for a sort function through all loaded packages, versus only in the reshape package:

??sort           # Find functions that include the keyword 'sort'
??reshape::sort  # Limit search to the reshape package

Read error messages!

As well as using the help files, we encourage you to carefully read any error messages that arise as you try to run your code

R tries to give you clues about where the errors in your code lie

These clues can sometimes be quite cryptic, but it’s worth reading them to see if you can decipher what they mean, as this will ultimately help you on your journey to become independent and capable coders