Computing

The tips on this page involve getting help from within the :R environment. Be aware that R’s internal help documentation is typically most useful when you already have some idea of which functions you need to use, or at least have it narrowed down to a few possibilities. In that case, the documentation provides crisp clarification of function usage, arguments, and return values. The documentation also provides some nice “See Also” cross-referencing (usually), allowing you to discover related functions. And occasionally there are useful examples, although this is hit-or-miss.

For help beyond what’s in the internal documentation, you may want to start with the links provided on the main :R wiki page, along with material posted at the NCEAS R Programming Language Resource Center. Keep in mind that there are undoubtedly many others out there who have tackled similar problems, and at least a few of them probably posted something on the internet; if all else fails, let Google be your guide!

Get information about a specific function

:::rsplus
 # View internal help documentation
 > ?functionname
 # Another way to access help files (useful because it comes with other options)
 > help(functionname)
 # What does the function need? Show arguments and default values:
 # (Note that this isn't very useful for "primitive" functions)
 > args(functionname)
 # How was the function programmed? Display its underlying code:
 > functionname     # note absence of parentheses
 # Similar to above, but just returns code body (useful for programming)
 > body(functionname)`</code>`


####  Get information about a package
The extent of documentation varies across packages, but there several different ways to dig up information about a particular package. All functions below assume that the package has already been installed.

`<code rsplus>`
 # View package description
 help(package="packagename")
 # ...or equivalently...
 library(help="packagename")`</code>`

The package description (retrieved above) will often list the functions provided by a package. However, this is not always the case. A more reliable way for listing all package functions is as follows:

`<code rsplus>`
 > require(packagename)  #First need to load the package
 > ls("package:packagename")`</code>`

Sometimes packages come with vignettes, which are typically short manuals and/or case studies written by the package developer. This information can be a nice complement to the technical function documentation. Vignettes can be viewed with a PDF reader, called directly from within the R environment.

`<code rsplus>`
 # List available vignettes (i.e. those currently on your system)
 > vignette()
 # View an available vignette
 > vignette("name_of_vignette")`</code>`

Note for Linux users: You may need to tweak your configuration settings to enable the proper PDF viewer. For example, if you have an Ubuntu workstation, you may want to tell R to view PDFs with evince instead of the default xpdf. Open /etc/R/Renvirons in a text editor, find the line containing R_PDFVIEWER, and replace xpdf with evince.

Lastly, documentation for all installed and base packages can be browsed with a web browser. See the help.start() tip below.


####  Search internal documentation using vague terms
`<code>`
 # Example search for help on contingency tables
 > help.search("contingency table")
 Help files with alias or concept or title matching ‘contingency table’
 using fuzzy matching:
 ftable(stats)           Flat Contingency Tables
 ftable.formula(stats)   Formula Notation for Flat Contingency Tables
 read.ftable(stats)      Manipulate Flat Contingency Tables
 Type 'help(FOO, package = PKG)' to inspect entry 'FOO(PKG) TITLE'.`</code>`


####  Open the full help documentation in an external web browser
`<code>`
 > help.start()`</code>`


####  Open web browser to search R-help list archives (and more)
`<code>`
 > RSiteSearch("your search terms")`</code>`


####  Install the R Site Search toolbar for Mozilla/Netscape
Seeking R help on the web using search engines like Google will often be useful, but may yield a high proportion of irrelevant results. After all, the letter "R" is not a particularly definitive search term. However, with a click of a button you can install a [[http://mycroft.mozdev.org/download.html?name=R+Site+search&sherlock=yes&submitform=Search|Mozilla R Site Search plug-in]] that can be used within Firefox (and related browsers) to search only among the R-help archives, R FAQs, and R documentation.