DATA MINING
Desktop Survival Guide by Graham Williams |
|||||
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
help.start:
> help.start() |
> options(htmlhelp=FALSE) |
Basic documentation is available through the help
function. Preceding any function name with a question mark
(?) will also invoke the help function. The
str and args 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 library function (see
Section for information on packages):
library(help=maptools) |
Often, more detailed documentation is provided through vignettes. To
list all the available vignettes call the vignette
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 edit with vignette 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
example function:
> example(persp) |
If you are looking for a specific function, you might want to use the
help.search function to search through R packages
that are installed on your system, or the RSiteSearch
function to search the CRAN archive:
> help.search("lda") > RSiteSearch("lda", restrict="function") |
> 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 plot function is called is determined according to
the type of object being plotted. If it is an rpart object,
then plot.rpart is actually called up to do the
plotting. For any such function you can get a list of candidate
methods with the methods 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-2006 [email protected] Support further development through the purchase of the PDF version of the book.