Helping Yourself
Before asking others for help, it’s generally a good idea for you totry to help yourself. R includes extensive facilities for accessingdocumentation and searching for help. There are also specialized searchengines for accessing information about R on the internet, and generalinternet search engines can also prove useful (see below).
R Help: help()
and?
The help()
function and ?
help operator inR provide access to the documentation pages for R functions, data sets,and other objects, both for packages in the standard R distribution andfor contributed packages. To access documentation for the standardlm
(linear model) function, for example, enter the commandhelp(lm)
or help("lm")
, or ?lm
or?"lm"
(i.e., the quotes are optional).
To access help for a function in a package that’s notcurrently loaded, specify in addition the name of the package: Forexample, to obtain documentation for the rlm()
(robustlinear model) function in the MASS package,help(rlm, package="MASS")
.
Standard names in R consist of upper- and lower-case letters,numerals (0-9
), underscores (_
), and periods(.
), and must begin with a letter or a period. To obtainhelp for an object with a non-standard name (such as the helpoperator ?
), the name must be quoted: for example,help('?')
or ?"?"
.
You may also use the help()
function to accessinformation about a package in your library — for example,help(package="MASS")
— which displays an index of availablehelp pages for the package along with some other information.
Help pages for functions usually include a section with executableexamples illustrating how the functions work. You can execute theseexamples in the current R session via the example()
command: e.g., example(lm)
.
Vignettesand Code Demonstrations: browseVignettes()
,vignette()
and demo()
Many packages include vignettes, which are discursivedocuments meant to illustrate and explain facilities in the package. Youcan discover vignettes by accessing the help page for a package, or viathe browseVignettes()
function: the commandbrowseVignettes()
opens a list of vignettes fromall of your installed packages in your browser, whilebrowseVignettes(package=package-name)
(e.g.,browseVignettes(package="survival")
) shows the vignettes,if any, for a particular package. vignette()
is employedsimilarly, but displays a list of vignettes in text form.
You can also use the vignette("vignette-name")
commandto view a vignette (possibly specifying the name of the package in whichthe vignette resides, if the vignette name is not unique): for example,vignette("timedep")
orvignette("timedep", package="survival")
(which are, in thiscase, equivalent).
Vignettes may also be accessed from the CRAN page for the package(e.g.survival), if youwish to review the vignette for a package prior to installing and/orusing it.
Packages may also include extended code demonstrations (“demos”). Thecommand demo()
lists all demos for all packages in yourlibrary, while demo(package="package-name")
(e.g.,demo(package="stats")
) lists demos in a particular package.To run a demo, call the demo()
function with the quotedname of the demo (e.g., demo("nlm")
), specifying the nameof the package if the name of the demo isn’t unique (e.g.,demo("nlm", package="stats")
, where, in this case, thepackage name need not be given explicitly).
Searching for Help Within R
The help()
function and ?
operator areuseful only if you already know the name of the function that you wishto use. There are also facilities in the standard R distribution fordiscovering functions and other objects. The following functions cast aprogressively wider net. Use the help system to obtain completedocumentation for these functions: for example,?apropos
.
apropos()
The apropos()
function searches for objects, includingfunctions, directly accessible in the current R session that have namesthat include a specified character string. This may be a literal stringor a regular expression to be used for pattern-matching (see?"regular expression"
). By default, string matching byapropos()
is case-insensitive. For example,apropos("^glm")
returns the names of all accessible objectsthat start with the (case-insensitive) characters"glm"
.
help.search()
and??
The help.search()
function scans the documentation forpackages installed in your library. The (first) argument tohelp.search()
is a character string or regular expression.For example, help.search("^glm")
searches for help pages,vignettes, and code demos that have help “aliases,” “concepts,” ortitles that begin (case-insensitively) with the characters"glm"
. The ??
operator is a synonym forhelp.search()
: for example, ??"^glm"
.
RSiteSearch()
RSiteSearch()
uses an internet search engine (also seebelow) to search for informationin function help pages and vignettes for all CRAN packages, and in CRANtask views (described below). Unlike theapropos()
and help.search()
functions,RSiteSearch()
requires an active internet connection anddoesn’t employ regular expressions. Braces may be used to specifymulti-word terms; otherwise matches for individual words are included.For example, RSiteSearch("{generalized linear model}")
returns information about R functions, vignettes, and CRAN task viewsrelated to the term "generalized linear model"
withoutmatching the individual words "generalized"
,"linear"
, or "model"
.
findfn()
and ???
in thesos package, which is not part of the standardR distribution but is available on CRAN, provide an alternativeinterface to RSiteSearch()
.
help.start()
help.start()
starts and displays a hypertext basedversion of R’s online documentation in your default browser thatprovides links to locally installed versions of the R manuals, a listingof your currently installed packages and other documentationresources.
R Help on the Internet
There are internet search sites that are specialized for R searches,including search.r-project.org (which isthe site used by RSiteSearch
) and Rseek.org.
It is also possible to use a general search site like Google, by qualifying the search with“R” or the name of an R package (or both). It can be particularlyhelpful to paste an error message into a search engine to find outwhether others have solved a problem that you encountered.
CRAN Task Views
CRAN Task Views are documents that summarize R resources on CRAN inparticular areas of application, helping your to navigate the maze ofthousands of CRAN packages. A list of available TaskViews may be found on CRAN.
R FAQs (Frequently AskedQuestions)
There are three primary FAQ listings which are periodically updatedto reflect very commonly asked questions by R users. There is a Main R FAQ, aWindowsspecific R FAQ and a Mac OS (OSX) specific R FAQ.
Asking for Help
If you find that you can’t answer a question or solve a problemyourself, you can ask others for help, either locally (if you knowsomeone who is knowledgeable about R) or on the internet. In order toask a question effectively, it helps to phrase the question clearly,and, if you’re trying to solve a problem, to include a small,self-contained, reproducible example of the problem that others canexecute. For information on how to ask questions, see, e.g., the Rmailing list posting guide,and the document about howto create reproducible examples for R on Stack Overflow.
Stack Overflow
Stack Overflow is a wellorganized and formatted site for help and discussions about programming.It has excellent searchability. Topics are tagged, and “r” is a very popular tagon the site with almost 150,000 questions (as of summer 2016). To godirectly to R-related topics, visit http://stackoverflow.com/questions/tagged/r.For an example both of the value of the site’s organization andinformation that is very useful to R users, see “Howto make a great R reproducible example?”, which is also mentionedabove.
R Email Lists
The R Project maintains a number of subscription-based email lists for posingand answering questions about R, including the general R-help emaillist, the R-devel listfor R code development, and R-package-devellist for developers of CRAN packages; lists for announcements about R and R packages;and a variety of more specialized lists. Before posing a question on oneof these lists, please read the R mailing listinstructions and the postingguide.