| 49507 |
ripley |
1 |
% File src/library/utils/man/Question.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 72539 |
murdoch |
3 |
% Copyright 1995-2017 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 49507 |
ripley |
6 |
\name{Question}
|
| 56186 |
murdoch |
7 |
\alias{Question}
|
| 27442 |
ripley |
8 |
\alias{?}
|
| 49507 |
ripley |
9 |
\title{Documentation Shortcuts}
|
| 27442 |
ripley |
10 |
\description{
|
|
|
11 |
These functions provide access to documentation.
|
|
|
12 |
Documentation on a topic with name \code{name} (typically, an \R
|
| 49507 |
ripley |
13 |
object or a data set) can be displayed by either \code{help("name")} or
|
| 27442 |
ripley |
14 |
\code{?name}.
|
|
|
15 |
}
|
| 49507 |
ripley |
16 |
% it is in fact `?`(e1, e2)
|
| 27442 |
ripley |
17 |
\usage{
|
| 54642 |
hornik |
18 |
\special{?topic}
|
| 37146 |
ripley |
19 |
|
| 54642 |
hornik |
20 |
\special{type?topic}
|
| 27442 |
ripley |
21 |
}
|
|
|
22 |
\arguments{
|
| 49507 |
ripley |
23 |
\item{topic}{Usually, a \link{name} or character string specifying the
|
|
|
24 |
topic for which help is sought.
|
| 27442 |
ripley |
25 |
|
| 49507 |
ripley |
26 |
Alternatively, a function call to ask for documentation on a
|
|
|
27 |
corresponding S4 method: see the section on S4 method documentation.
|
|
|
28 |
The calls \code{\var{pkg}::\var{topic}} and
|
|
|
29 |
\code{\var{pkg}:::\var{topic}} are treated specially, and look for
|
|
|
30 |
help on \code{topic} in package \pkg{\var{pkg}}.
|
|
|
31 |
}
|
| 27442 |
ripley |
32 |
\item{type}{the special type of documentation to use for this topic;
|
| 37146 |
ripley |
33 |
for example, if the type is \code{class}, documentation is
|
| 49482 |
ripley |
34 |
provided for the class with name \code{topic}.
|
|
|
35 |
See the Section \sQuote{S4 Method Documentation} for the uses of
|
|
|
36 |
\code{type} to get help on formal methods, including
|
|
|
37 |
\code{methods?\var{function}} and \code{method?\var{call}}.
|
|
|
38 |
}
|
| 27442 |
ripley |
39 |
}
|
|
|
40 |
\details{
|
| 49507 |
ripley |
41 |
This is a shortcut to \code{\link{help}} and uses its default type of help.
|
| 27442 |
ripley |
42 |
|
| 42954 |
ripley |
43 |
Some topics need to be quoted (by \link{backtick}s) or given as a
|
|
|
44 |
character string. There include those which cannot syntactically
|
| 49482 |
ripley |
45 |
appear on their own such as unary and binary operators,
|
| 42954 |
ripley |
46 |
\code{function} and control-flow \link{reserved} words (including
|
|
|
47 |
\code{if}, \code{else} \code{for}, \code{in}, \code{repeat},
|
| 74363 |
maechler |
48 |
\code{while}, \code{break} and \code{next}). The other \code{reserved}
|
| 42954 |
ripley |
49 |
words can be used as if they were names, for example \code{TRUE},
|
|
|
50 |
\code{NA} and \code{Inf}.
|
| 49482 |
ripley |
51 |
}
|
| 38409 |
ripley |
52 |
|
|
|
53 |
\section{S4 Method Documentation}{
|
| 49507 |
ripley |
54 |
Authors of formal (\sQuote{S4}) methods can provide documentation
|
| 27442 |
ripley |
55 |
on specific methods, as well as overall documentation on the methods
|
|
|
56 |
of a particular function. The \code{"?"} operator allows access to
|
|
|
57 |
this documentation in three ways.
|
|
|
58 |
|
| 49482 |
ripley |
59 |
The expression \code{methods?\var{f}} will look for the overall
|
|
|
60 |
documentation methods for the function \code{\var{f}}. Currently,
|
|
|
61 |
this means the documentation file containing the alias
|
|
|
62 |
\code{\var{f}-methods}.
|
| 27652 |
maechler |
63 |
|
| 27442 |
ripley |
64 |
There are two different ways to look for documentation on a
|
|
|
65 |
particular method. The first is to supply the \code{topic} argument
|
|
|
66 |
in the form of a function call, omitting the \code{type} argument.
|
|
|
67 |
The effect is to look for documentation on the method that would be
|
|
|
68 |
used if this function call were actually evaluated. See the examples
|
|
|
69 |
below. If the function is not a generic (no S4 methods are defined
|
|
|
70 |
for it), the help reverts to documentation on the function name.
|
|
|
71 |
|
| 49507 |
ripley |
72 |
The \code{"?"} operator can also be called with \code{doc_type} supplied
|
| 49482 |
ripley |
73 |
as \code{method}; in this case also, the \code{topic} argument is
|
| 27442 |
ripley |
74 |
a function call, but the arguments are now interpreted as specifying
|
|
|
75 |
the class of the argument, not the actual expression that will
|
|
|
76 |
appear in a real call to the function. See the examples below.
|
| 27652 |
maechler |
77 |
|
| 27442 |
ripley |
78 |
The first approach will be tedious if the actual call involves
|
|
|
79 |
complicated expressions, and may be slow if the arguments take a
|
|
|
80 |
long time to evaluate. The second approach avoids these
|
| 49507 |
ripley |
81 |
issues, but you do have to know what the classes of the actual
|
| 27442 |
ripley |
82 |
arguments will be when they are evaluated.
|
|
|
83 |
|
|
|
84 |
Both approaches make use of any inherited methods; the signature of
|
|
|
85 |
the method to be looked up is found by using \code{selectMethod}
|
| 72539 |
murdoch |
86 |
(see the documentation for \code{\link{getMethod}}). A limitation
|
|
|
87 |
is that methods in packages (as opposed to regular functions) will only
|
|
|
88 |
be found if the package exporting them is on the search list, even
|
|
|
89 |
if it is specified explicitly using the \code{?package::generic()}
|
|
|
90 |
notation.
|
| 27442 |
ripley |
91 |
}
|
|
|
92 |
\references{
|
|
|
93 |
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
|
|
|
94 |
\emph{The New S Language}.
|
| 47262 |
ripley |
95 |
Wadsworth & Brooks/Cole.
|
| 27442 |
ripley |
96 |
}
|
|
|
97 |
\seealso{
|
| 49507 |
ripley |
98 |
\code{\link{help}}
|
| 27442 |
ripley |
99 |
|
| 49507 |
ripley |
100 |
\code{\link{??}} for finding help pages on a vague topic.
|
| 27442 |
ripley |
101 |
}
|
|
|
102 |
\examples{
|
| 49507 |
ripley |
103 |
?lapply
|
| 27442 |
ripley |
104 |
|
| 49507 |
ripley |
105 |
?"for" # but quotes/backticks are needed
|
| 42954 |
ripley |
106 |
?`+`
|
| 27442 |
ripley |
107 |
|
|
|
108 |
?women # information about data set "women"
|
|
|
109 |
|
|
|
110 |
\dontrun{
|
| 30946 |
ripley |
111 |
require(methods)
|
|
|
112 |
## define a S4 generic function and some methods
|
| 27442 |
ripley |
113 |
combo <- function(x, y) c(x, y)
|
|
|
114 |
setGeneric("combo")
|
| 30946 |
ripley |
115 |
setMethod("combo", c("numeric", "numeric"), function(x, y) x+y)
|
| 27442 |
ripley |
116 |
|
| 44243 |
ripley |
117 |
## assume we have written some documentation
|
|
|
118 |
## for combo, and its methods ....
|
| 27442 |
ripley |
119 |
|
| 49507 |
ripley |
120 |
?combo # produces the function documentation
|
| 27442 |
ripley |
121 |
|
| 49507 |
ripley |
122 |
methods?combo # looks for the overall methods documentation
|
| 27442 |
ripley |
123 |
|
| 49507 |
ripley |
124 |
method?combo("numeric", "numeric") # documentation for the method above
|
| 27442 |
ripley |
125 |
|
| 49507 |
ripley |
126 |
?combo(1:10, rnorm(10)) # ... the same method, selected according to
|
|
|
127 |
# the arguments (one integer, the other numeric)
|
| 27442 |
ripley |
128 |
|
| 49507 |
ripley |
129 |
?combo(1:10, letters) # documentation for the default method
|
| 30946 |
ripley |
130 |
}}
|
| 27442 |
ripley |
131 |
\keyword{documentation}
|