Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

R Documentation

R provides extensive on-line documentation, some of which is very good, but there is quite a degree of variability and often the novice is left with complex concepts to come to grips with or 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, Wikipedia provides some good basic introductions to the concepts. The R Wiki is another resource. The R-help mailing list is a very active mailing list that will generally answer serious questions very quickly.

As we have seen above we can view documentation within the R console through the help function or the ? shortcut. We can also use an external web browser through a call to the help.start function:



> 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 Roption[]htmlhelp option:



> options(htmlhelp=FALSE)

While basic documentation is available through the help function (or ?) the str (structure) and args (arguments) functions are also useful for quickly listing the signature of the function.



> args(dim)



function (x) 
NULL

This tells us that the dim function takes a single argument, called Roptionx.



> args(scale)



function (x, center = TRUE, scale = TRUE) 
NULL

Here we see that the function scale takes one mandatory argument (Roptionx) and two optional arguments (Roptioncenter and Roptionscale). If the optional arguments are not supplied then the defaults as indicated here (TRUE for both) will be used.



> args(max)



function (..., na.rm = FALSE) 
NULL

This shows another common syntactic element of R: the ellipses. This indicates that any number of arguments can be supplied. These arguments might be used within the function, or passed on to another function within max. We also see an optional argument, Roptionna.rm, together with its default value.

To obtain a basic overview of a package you can use the Roption[]help option of the library function (see Section 28.3 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()

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 else the RSiteSearch function to search the CRAN archive:



> RSiteSearch("lda", restrict="function")

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



> apropos("rat")	 # 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 to do the plotting. For any such function you can get a list of candidate methods with the methods function.



> methods(plot)



 [1] plot.aareg*              plot.acf*               
 [3] plot.agnes*              plot.correspondence*    
 [5] plot.cox.zph*            plot.data.frame*        
 [7] plot.Date*               plot.decomposed.ts*     
 [9] plot.default             plot.dendrogram*        
[11] plot.density             plot.diana*             
[13] plot.DocumentTermMatrix* plot.ecdf               
[15] plot.ensemble            plot.error              
[17] plot.factor*             plot.formula*           
[19] plot.goodfit*            plot.hclust*            
[21] plot.histogram*          plot.HoltWinters*       
[23] plot.isoreg*             plot.lda*               
[25] plot.lm                  plot.loglm*             
[27] plot.mca*                plot.medpolish*         
[29] plot.mlm                 plot.mona*              
[31] plot.oddsratio*          plot.partition*         
[33] plot.POSIXct*            plot.POSIXlt*           
[35] plot.ppr*                plot.prcomp*            
[37] plot.princomp*           plot.profile*           
[39] plot.profile.nls*        plot.proximity          
[41] plot.ridgelm*            plot.rpart*             
[43] plot.rsf                 plot.shingle*           
[45] plot.silhouette*         plot.spec               
[47] plot.spec.coherency      plot.spec.phase         
[49] plot.spline*             plot.stepfun            
[51] plot.stl*                plot.structable*        
[53] plot.survfit*            plot.table*             
[55] plot.TermDocumentMatrix* plot.trellis*           
[57] plot.ts                  plot.tskernel*          
[59] plot.TukeyHSD            plot.variable           
[61] plot.Weka_tree*          plot.xyVector*          

   Non-visible functions are asterisked

Finally, note 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 ? shorthand by quoting the function name:



> ?"[" # 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-2010 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010