快捷搜索:

Getting Help with R

Before asking others for help, its generally a good idea for you to try to help yourself. R includes extensive facilities for accessing documentation and searching for help. There are also specialized search engines for accessing information about R on the internet, and general internet search engines can also prove useful (see below).

Thehelp()function and?help operator in R provide access to the documentation pages for R functions, data sets, and other objects, both for packages in the standard R distribution and for contributed packages. To access documentation for the standardlm(linear model) function, for example, enter the commandhelp(lm)orhelp(lm), or?lmor?lm(i.e., the quotes are optional).

To access help for a function in a package thatsnotcurrently loaded, specify in addition the name of the package: For example, to obtain documentation for therlm()(robust linear model) function in theMASSpackage,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 obtain help for an object with anon-standardname (such as the help operator?), the name must be quoted: for example,help(?)or??.

You may also use thehelp()function to access information about a package in your library for example,help(package=MASS) which displays an index of available help pages for the package along with some other information.

Help pages for functions usually include a section with executable examples illustrating how the functions work. You can execute these examples in the current R session via theexample()command: e.g.,example(lm).

Many packages includevignettes, which are discursive documents meant to illustrate and explain facilities in the package. You can discover vignettes by accessing the help page for a package, or via thebrowseVignettes()function: the commandbrowseVignettes()opens a list of vignettes fromallof 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 employed similarly, but displays a list of vignettes in text form.

You can also use thevignette(vignette-name)command to view a vignette (possibly specifying the name of the package in which the vignette resides, if the vignette name is not unique): for example,vignette(timedep)orvignette(timedep, package=survival)(which are, in this case, equivalent).

Vignettes may also be accessed from the CRAN page for the package (e.g.survival), if you wish to review the vignette for a package prior to installing and/or using it.

Packages may also include extended code demonstrations (demos). The commanddemo()lists all demos for all packages in your library, whiledemo(package=package-name)(e.g.,demo(package=stats)) lists demos in a particular package. To run a demo, call thedemo()function with the quoted name of the demo (e.g.,demo(nlm)), specifying the name of the package if the name of the demo isnt unique (e.g.,demo(nlm, package=stats), where, in this case, the package name need not be given explicitly).

Thehelp()function and?operator are useful only if you already know the name of the function that you wish to use. There are also facilities in the standard R distribution for discovering functions and other objects. The following functions cast a progressively wider net. Use the help system to obtain complete documentation for these functions: for example,?apropos.

Theapropos()function searches for objects, including functions, directly accessible in the current R session that have names that include a specified character string. This may be a literal string or aregular expressionto 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 objects that start with the (case-insensitive) charactersglm.

Thehelp.search()function scans the documentation for packages 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, or titles that begin (case-insensitively) with the charactersglm. The??operator is a synonym forhelp.search(): for example,??^glm.

RSiteSearch()uses aninternet search engine(also seebelow) to search for information in function help pages and vignettes for all CRAN packages, and in CRAN task views (describedbelow). Unlike theapropos()andhelp.search()functions,RSiteSearch()requires an active internet connection and doesnt employ regular expressions. Braces may be used to specify multi-word terms; otherwise matches for individual words are included. For example,RSiteSearch(generalized linear model)returns information about R functions, vignettes, and CRAN task views related to the termgeneralized linear modelwithout matching the individual wordsgeneralized,linear, ormodel.

findfn()and???in thesospackage, which isnotpart of the standard R distribution but is available on CRAN, provide an alternative interface toRSiteSearch().

help.start()starts and displays a hypertext based version of Rs online documentation in your default browser that provides links to locally installed versions of the R manuals, a listing of your currently installed packages and other documentation resources.

There are internet search sites that are specialized for R searches, (which is the site used byRSiteSearch) andRseek.org.

It is also possible to use a general search site likeGoogle, by qualifying the search with R or the name of an R package (or both). It can be particularly helpful to paste an error message into a search engine to find out whether others have solved a problem that you encountered.

CRAN Task Views are documents that summarize R resources on CRAN in particular areas of application, helping your to navigate the maze of thousands of CRAN packages. Alist of available Task Viewsmay be found on CRAN.

There are three primary FAQ listings which are periodically updated to reflect very commonly asked questions by R users. There is aMain R FAQ, aWindows specific R FAQand aMac OS (OS X) specific R FAQ.

If you find that you cant answer a question or solve a problem yourself, you can ask others for help, either locally (if you know someone who is knowledgeable about R) or on the internet. In order to ask a question effectively, it helps to phrase the question clearly, and, if youre trying to solve a problem, to include a small, self-contained, reproducible example of the problem that others can execute. For information on how to ask questions, see, e.g., the R mailing listposting guide, and the document abouthow to create reproducible examples for Ron Stack Overflow.

Stack Overflowis a well organized and formatted site for help and discussions about programming. It has excellent searchability. Topics are tagged, andr is a very popular tag on the sitewith almost 150,000 questions (as of summer 2016). To go directly to R-related topics, visit For an example both of the value of the sites organization and information that is very useful to R users, seeHow to make a great R reproducible example?, which is also mentioned above.

The R Project maintains a number of subscription-basedemail listsfor posing and answering questions about R, including the generalR-helpemail list, theR-devellist for R code development, andR-package-devellist for developers of CRAN packages; lists for announcements aboutRandR packages; and a variety of more specialized lists. Before posing a question on one of these lists, please read theR mailing list instructionsand theposting guide.

您可能还会对下面的文章感兴趣: