Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Help

R provides extensive on-line documentation, some of which is very good, but there is a degree of variability and often the novice is left with a pointer to a paper in a research journal that requires a degree in statistics to read! But, as is the power of open source software, anyone is welcome to improve the situation by contributing better documentation. Also, the on-line Wikipedia is becoming a great tool for understanding the basic concepts.

You can view documentation either within the R window or else through an external web browser through the call to XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionshelp.start:

> help.start()

Once this call has been made, all following help requests are displayed in the web browser. You can turn this off with the htmlhelp option:

> options(htmlhelp=FALSE)

Basic documentation is available through the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionshelp function. Preceding any function name with a question mark (XnullXXnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)XnullXR functionsR functions?) will also invoke the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionshelp function. The XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsstr and XnullXXnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)XnullXR functionsR functionsargs functions are also useful in listing the signature of the function:

> help(scale)	# Display the manual page for the scale function.
> ?scale	# Same as help(scale).
> str(scale)    # Show the structure of the function call.
function (x, center = TRUE, scale = TRUE)
> args(scale)
function (x, center = TRUE, scale = TRUE)
NULL

To obtain a basic overview of a package you can use the help option of the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionslibrary function (see Section 13.6 for information on packages):

library(help=maptools)

Often, more detailed documentation is provided through vignettes. To list all the available vignettes call the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsvignette function without any arguments. Then to view a specific vignette simply pass it as an argument. Of particular use is the combination of the R function XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsedit with XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsvignette which will place you in a text editor with the sample code from the vignette, giving you an opportunity to try the code out.

> vignette()
Vignettes in package 'arules':

arules       Data structures for association rules (source, pdf)
[...]
> vignette("arules")
> edit(vignette("arules"))

Most packages provide examples of their usage with the basic documentation. You can run the examples through R using the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsexample function:

> example(persp)

If you are looking for a specific function, you might want to use the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionshelp.search function to search through R packages that are installed on your system, or the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsRSiteSearch function to search the CRAN archive:

> help.search("lda")		         
> RSiteSearch("lda", restrict="function")

The following rely on the function being identified in the current session (i.e., they are already attached):

> find(lda)		# 
> apropos("abc")	# List objects matching the string.
> getAnywhere(lda)	# Provides useful description of source.

Being an object-oriented language, R provides multiple implementations for numerous functions (or methods). For example, which XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsplot function is called is determined according to the type of object being plotted. If it is an rpart object, then XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsplot.rpart is actually called up to do the plotting. For any such function you can get a list of candidate methods with the XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsmethods function.

> methods(plot)
 [1] plot.Date*          plot.HoltWinters*   plot.POSIXct*
 [4] plot.POSIXlt*       plot.TukeyHSD       plot.acf*
 [7] plot.data.frame*    plot.decomposed.ts* plot.default
[10] plot.dendrogram*    plot.density        plot.ecdf
[13] plot.factor*        plot.formula*       plot.hclust*
[16] plot.histogram*     plot.isoreg*        plot.lm
[19] plot.medpolish*     plot.mlm            plot.ppr*
[22] plot.prcomp*        plot.princomp*      plot.profile.nls*
[25] plot.rpart*         plot.spec           plot.spec.coherency
[28] plot.spec.phase     plot.stepfun        plot.stl*
[31] plot.table*         plot.ts             plot.tskernel*

   Non-visible functions are asterisked

Noting that the open square bracket is actually an operator which extracts or replaces parts of an object, we can get help on such operators, and their specific methods, using the same notation:

> ?"["		    # Help on the [ operator
> ?"[.factor"       # Help on the [ operator when applied to a factor
> ?"[<-.data.frame" # Help on the data frame replace operator

Copyright © 2004-2008 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
PDF version is properly formatted and forms a comprehensive book (draft with over 600 pages).
Brought to you by Togaware.