R Programming/Documentation

From Wikibooks, open books for an open world
Jump to: navigation, search

Obtaining Help[edit]

For each package you have a reference manual available as an HTML file from within R or as a PDF on the CRAN website. You also often have Vignettes or comprehensive articles in the R Journal, the Journal of Statistical Software, etc.

>library(help="package_name")
>vignette("np",package="np")
>vignette(all=FALSE) # vignettes for all attached packages
>vignette(all=TRUE) # vignettes for all packages on the computer

You can search for help inside all loaded packages using help() or ?. Usually you do not need to add quotes to function names, but sometimes it can be useful. args() gives the full syntax of a function.

> help(lm)
> ?lm
> ?"for"
> ?"[["
> args("lm")
function (formula, data, subset, weights, na.action, method = "qr", 
    model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
    contrasts = NULL, offset, ...) 
NULL

apropos() and find() looks for all the functions in the loaded packages containing a keyword or a regular expression[1].

> apropos("norm")
  [1] "dlnorm"         "dnorm"          "plnorm"        
  [4] "pnorm"          "qlnorm"         "qnorm"         
  [7] "qqnorm"         "qqnorm.default" "rlnorm"        
 [10] "rnorm"          "normalizePath"

You can search for help in all installed packages using help.search() or its shortcut ??.

> ??"lm"
> help.search("covariance")

RSiteSearch() looks for help in all packages and in the R mailing lists. The sos package improves the RSiteSearch() function with the findFn() function. ??? is a wrapper for findFn().

> RSiteSearch("spline")
> library("sos")
> findFn("spline", maxPages = 2)
> ???"spline"(2)

hints() in the hints package suggests what to do with an object.

> fit <- lm(y ~ x)
> library("hints")
> hints(fit) # returns a list of function using lm objects.

Handouts[edit]

Reference Sheet[edit]

Teaching Resources[edit]

Blogs[edit]

Journals[edit]

Books[edit]

useR and other R conferences[edit]

Search Engine[edit]

Q&A / Forums[edit]

References[edit]

  1. If you want to know more about regular expressions, have a look at the Regular expressions section in the Text Processing page.
  2. Introduction to Data Analysis
Previous: Data types Index Next: Sample Session