Rev 59039 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/methods/man/Documentation.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2007 R Core Team% Distributed under GPL 2 or later\name{Documentation}\alias{Documentation}\alias{Documentation-class}\alias{Documentation-methods}\title{Using and Creating On-line Documentation for Classes andMethods}\description{Special documentation can be supplied to describe theclasses and methods that are created by the software in the methodspackage. Techniques to access this documentation and to create itin R help files are described here.}\section{Getting documentation on classes and methods}{You can ask for on-line help for class definitions, for specificmethods for a generic function, and for general discussion ofmethods for a generic function. These requests use the \code{?}operator (see \code{\link{help}} for a general description ofthe operator). Of course, you are at the mercy of the implementeras to whether there \emph{is} any documentation on the correspondingtopics.Documentation on a class uses the argument \code{class} on the leftof the \code{?}, and the name of the class on the right; forexample,\code{class ? genericFunction}to ask for documentation on the class \code{"genericFunction"}.When you want documentation for the methods defined for a particularfunction, you can ask either for a general discussion of the methodsor for documentation of a particular method (that is, the method thatwould be selected for a particular set of actual arguments).Overall methods documentation is requested bycalling the \code{?} operator with \code{methods} as the left-sideargument and the name of the function as the right-side argument. Forexample,\code{methods ? initialize}asks for documentation on the methods for the \code{\link{initialize}}function.Asking for documentation on a particular method is done by giving afunction call expression as the right-hand argument to the \code{"?"}operator. There are two forms, depending on whether you prefer togive the class names for the arguments or expressions that you intendto use in the actual call.If you planned to evaluate a function call, say \code{myFun(x, sqrt(wt))}and wanted to find out something about the method that would be usedfor this call, put the call on the right of the \code{"?"} operator:\code{?myFun(x, sqrt(wt))}A method will be selected, as it would be for the call itself, anddocumentation for that method will be requested. If \code{myFun} isnot a generic function, ordinary documentation for the function willbe requested.If you know the actual classes for which you would like methoddocumentation, you can supply these explicitly in place of theargument expressions. In the example above, if you want methoddocumentation for the first argument having class \code{"maybeNumber"}and the second \code{"logical"}, call the \code{"?"} operator, thistime with a left-side argument \code{method}, and with a function callon the right using the class names as arguments:\code{method ? myFun("maybeNumber", "logical")}Once again, a method will be selected, this time corresponding to thespecified classes, and method documentation will be requested. Thisversion only works with generic functions.The two forms each have advantages. The version with actual argumentsdoesn't require you to figure out (or guess at) the classes of thearguments.On the other hand, evaluating the arguments may take some time,depending on the example.The version with class names does require you to pick classes, butit's otherwise unambiguous. It has a subtler advantage, in that theclasses supplied may be virtual classes, in which case no actualargument will have specifically this class. The class\code{"maybeNumber"}, for example, might be a class union (see theexample for \code{\link{setClassUnion}}).In either form, methods will be selected as they would be in actualcomputation, including use of inheritance and group genericfunctions. See \code{\link{selectMethod}} for the details, since it isthe function used to find the appropriate method.}\section{Writing Documentation for Methods}{The on-line documentation for methods and classes uses some extensionsto the R documentation format to implement the requests for class andmethod documentation described above. See the document \emph{WritingR Extensions} for the available markup commands (you shouldhave consulted this document already if you are at the stage ofdocumenting your software).In addition to the specific markup commands to be described, you cancreate an initial, overall file with a skeleton of documentation forthe methods defined for a particular generic function:\code{promptMethods("myFun")}will create a file, \file{myFun-methods.Rd} with a skeleton ofdocumentation for the methods defined for function \code{myFun}.The output from \code{promptMethods} is suitable if you want todescribe all or most of the methods for the function in one file,separate from the documentation of the generic function itself.Once the file has been filled in and moved to the \file{man}subdirectory of your source package, requests for methodsdocumentation will use that file, both for specific methodsdocumentation as described above, and for overall documentationrequested by\code{methods ? myFun}You are not required to use \code{promptMethods}, and if you do, youmay not want to use the entire file created:\itemize{\item If you want to document the methods in the file containing thedocumentation for the generic function itself, you cancut-and-paste to move the \verb{\alias} lines and the\code{Methods} section from the file created by\code{promptMethods} to the existing file.\item On the other hand, if these are auxiliary methods, and you onlywant to document the added or modified software, you should stripout all but the relevant \verb{\alias} lines for the methods ofinterest, and remove all but the corresponding \verb{\item}entries in the \code{Methods} section. Note that in this case youwill usually remove the first \verb{\alias} line as well, sincethat is the marker for general methods documentation on thisfunction (in the example, \samp{\alias\{myfun-methods\}}).}If you simply want to direct documentation for one or more methods toa particular R documentation file, insert the appropriate alias.}\keyword{programming}\keyword{methods}\keyword{classes}\keyword{documentation}