Basic skills in R: Getting help
Help available inside R and RStudio
If you're starting with R you will regularly encounter errors, warnings, messages, and other problems. No one can work with without errors. This theory page explains how you can get help from within R and RStudio.
Getting hints from RStudio Suppose that you want to use the function ls()
to inspect the structure of a dataset, say the built-in dataset airquality
. While entering it in the console, you can already get suggestions on how to use the function!
We enter this function in the console. Normally, we would fill in the name of the dataset within the parentheses, but this time, we intentionally leave it empty. When we place our mouse cursor between the parentheses and press Tab, R automatically provides us with a list of all possible input options:
In the yellow text, there is a brief explanation of the selected field. Below it, it mentions that you can press F1 for more help. When we do this, in the bottom right panel under "Help," we receive a comprehensive description of the function and the various input options.
Asking for immediate help You can also directly request help and obtain a detailed description of a function, such as ls()
. To do so, enter help("ls")
in the console, or simply use the shorter version ?ls
.
Structure of a help message Instead of entering a help request like ?mean
, you can also use the search tool in the lower right panel Help. See the screen shot below.
The structure of the help is always the same, except that irrelevant parts are omitted:
-
Description: A short description what the function does.
-
Usage: Here you see all the function arguments (i.e. the information you need to give to the function).
-
Arguments: A detailed description of the function arguments.
-
Details: Usually, mathematical details about the implementation.
-
Value: A description of what the function returns.
-
Author(s): Who wrote the function. If you have a question or find a bug you may contact the author.
-
References: More information about the methods and how to cite them.
-
See Also: Links to other related functions.
-
Examples: This is perhaps the most useful part for a beginner. Here you find examples how the function is used. Copy them into the console and inspect the objects that are passed, what arguments are used and what the output is.
R help functions As you have seen above, the built-in help system provides details, references, and examples of any function contained in a currently installed package. You can obtain help by executing any of functions listed in table below.
Function | Action |
help.start() |
Invoke a help system. |
help("foo") or ?foo |
Get help on foo . |
help(package = "foo") |
Get help on the package foo . |
help.search("foo") or ??foo |
Search the help system for instances of the string foo . |
example("foo") |
Provide examples of function foo (quotation marks optional). |
data() |
List all available datasets contained in currently activated packages. |
vignette() |
List all available vignettes for currently installed packages. |
vignette("foo") |
Display specific vignettes for topic foo . |
The function help.start()
opens a browser window with access to introductory and advanced manuals, FAQs, and reference materials. The vignettes returned by the function vignette()
are practical introductory articles provided in PDF or HTML format. Not all packages have vignettes.