The R Project SVN R

Rev

Rev 86407 | Details | Compare with Previous | Last modification | View Log | RSS feed

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