How to Traverse Data with Apply Functions in R
How to Loop Through Values in R
An Overview of the Base Plot Function in R

How to Use the R Help Files

Sometimes you don’t know the exact function to use in R. Other times, you may know exactly what you need. Either way, the R Help Files can be, well…helpful.

When you know what R function you want

If you know the name of the function you need help with, you can access the R Help files in two ways:

  • By typing help(...) with the function name inside the brackets. For example, typing help(paste) returns help about the paste() function.

  • By typing ? followed by the name of the function. For example, typing ?paste returns help about the paste() function.

Typically, the R Help files follow a fairly standard outline. You find most of the following sections in every R Help file:

  • Title: A one-sentence overview of the function.

  • Description: An introduction to the high-level objectives of the function, typically about one paragraph long.

  • Usage: A description of the syntax of the function (in other words, how the function is called). This is where you find all the arguments that you can supply to the function, as well as any default values of these arguments.

  • Arguments: A description of each argument. Usually this includes a specification of the class (for example, character, numeric, list, and so on). This section is an important one to understand, because arguments are frequently a cause of errors in R.

  • Details: Extended details about how the function works, provides longer descriptions of the various ways to call the function (if applicable), and a longer discussion of the arguments.

  • Value: A description of the class of the value returned by the function.

  • See also: Links to other relevant functions. In most of the R editors, you can click these links to read the Help files for these functions.

  • Examples: Worked examples of real R code that you can paste into your console and run.

When you don’t know exactly what you need

Maybe you know the name of the function but you can’t remember whether it’s spelled in all lowercase letters or with some uppercase letters. In these situations, search the R Help files.

You can search the R Help files by typing with a quoted search term inside the brackets. This gives a list of functions that are similar to the search term; it’s useful if you can’t remember the exact name of a function. For example, typing"date") in the console returns a long list of possible matches, including format.Date, as.POSIXlt, and DateTimeClasses, among others.

Typing two question marks followed by the search term is a shortcut for For example, typing ??date returns the same list of functions as typing"date") does.

When you search for R help, you get a list of topics that match the search term. You may get the following result when typing ??date:

ada::update.ada            Add more trees to an ada object
chron::chron               Create a Chronological Object
chron::cut.dates           Create a Factor from a Chron or Dates Object
chron::dates               Generate Dates and Times Components from Input
base::Date                 Date Class
base::DateTimeClasses      Date-Time Classes
base::diff                 Lagged Differences

The left-hand column contains the functions that match your search term, and the right-hand column contains the R Help file title for this function. Each function consists of two elements separated by two colons. This means that in the package ada, there is a function called update.ada().

From the description of ada::update, it’s apparent that this function has nothing to do with dates. Nonetheless, it was included in the search results because the function name contained the substring date. If you scroll down the list, you’ll also find references to several date functions in the base package, including Date(), DateTimeClasses(), and diff().

After you’ve identified a helpful function, type ?functionName to open the relevant Help page.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
How to Work with Non-CSV Data Files in R
How to Access Alternative Resources for Help with R
How to Create a Function in R
How to Use Loops with Indices in R
How to Create Vectors in R