The R Project SVN R

Rev

Rev 30912 | Rev 39360 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30912 Rev 33634
Line 38... Line 38...
38
MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs,
38
MethodsListSelect(f, env, mlist, fEnv, finalDefault, evalArgs,
39
                  useInherited, fdef, resetAllowed)
39
                  useInherited, fdef, resetAllowed)
40
 
40
 
41
}
41
}
42
\arguments{
42
\arguments{
43
  \item{f}{ The character-string name of the generic function.
43
  \item{f}{The character-string name of the generic function.}
44
 
-
 
45
    }
-
 
46
  \item{signature}{ The signature of classes to match to the arguments
44
  \item{signature}{the signature of classes to match to the arguments
47
    of \code{f}.  See the details below.
45
    of \code{f}.  See the details below.
48
 
46
 
49
    For \code{selectMethod}, the signature can optionally be an
47
    For \code{selectMethod}, the signature can optionally be an
50
    environment with classes assigned to the names of the corresponding
48
    environment with classes assigned to the names of the corresponding
51
    arguments.  Note:  the names correspond to the names of the classes, \emph{not}
49
    arguments.  Note:  the names correspond to the names of the classes, \emph{not}
52
    to the objects supplied in a call to the generic function.  (You
50
    to the objects supplied in a call to the generic function.  (You
53
    are not likely to find this approach convenient, but it is used
51
    are not likely to find this approach convenient, but it is used
54
    internally and is marginally more efficient.)
52
    internally and is marginally more efficient.)
55
  }
53
  }
56
  \item{where}{ The position or environment in which to look for the method(s):  by default,
54
  \item{where}{The position or environment in which to look for the
57
      anywhere in
-
 
58
    the current search list.}
55
    method(s):  by default, anywhere in the current search list.}
59
  \item{optional}{ If the selection does not produce a unique result,
56
  \item{optional}{ If the selection does not produce a unique result,
60
    an error is generated, unless this argument is \code{TRUE}.  In that
57
    an error is generated, unless this argument is \code{TRUE}.  In that
61
    case, the value returned is either a \code{MethodsList} object, if
58
    case, the value returned is either a \code{MethodsList} object, if
62
    more than one method matches this signature, or \code{NULL} if no
59
    more than one method matches this signature, or \code{NULL} if no
63
    method matches.}
60
    method matches.}
Line 66... Line 63...
66
    generic function.  To restrict the search to a particular package
63
    generic function.  To restrict the search to a particular package
67
    or environment, e.g., supply this argument as
64
    or environment, e.g., supply this argument as
68
    \code{getMethodsMetaData(f,where)}.  For \code{selectMethod}, see
65
    \code{getMethodsMetaData(f,where)}.  For \code{selectMethod}, see
69
    the discussion of argument \code{fdef}.
66
    the discussion of argument \code{fdef}.
70
    }
67
    }
71
 
-
 
72
  \item{fdef}{In \code{selectMethod}, the \code{MethodsList} object
68
  \item{fdef}{In \code{selectMethod}, the \code{MethodsList} object
73
    and/or the generic function object can be explicitly supplied.  (Unlikely to be used, except in the
69
    and/or the generic function object can be explicitly supplied.
-
 
70
    (Unlikely to be used, except in the recursive call that finds
74
    recursive call that finds matches to more than one argument.)}
71
    matches to more than one argument.)}
75
 
-
 
76
  \item{env}{The environment in which argument evaluations are done in
72
  \item{env}{The environment in which argument evaluations are done in
77
    \code{MethodsListSelect}.  Currently must be supplied, but should
73
    \code{MethodsListSelect}.  Currently must be supplied, but should
78
    usually be \code{sys.frame(sys.parent())} when calling the function
74
    usually be \code{sys.frame(sys.parent())} when calling the function
79
    explicitly for debugging purposes.}
75
    explicitly for debugging purposes.}
80
  \item{fEnv, finalDefault, evalArgs, useInherited, resetAllowed}{ Internal-use
76
  \item{fEnv, finalDefault, evalArgs, useInherited, resetAllowed}{ Internal-use
Line 154... Line 150...
154
  sense that the evaluator code constructs and executes a call to
150
  sense that the evaluator code constructs and executes a call to
155
  \code{MethodsListSelect} when it does not already have a cached method
151
  \code{MethodsListSelect} when it does not already have a cached method
156
  for this generic function and signature.  (The value returned is
152
  for this generic function and signature.  (The value returned is
157
  stored by the evaluator so that the search is not required next
153
  stored by the evaluator so that the search is not required next
158
  time.)
154
  time.)
159
 
-
 
160
 
-
 
161
}
155
}
162
\value{
156
\value{
163
  The call to \code{selectMethod} or \code{getMethod} returns a
157
  The call to \code{selectMethod} or \code{getMethod} returns a
164
  \code{\link{MethodDefinition-class}} object, the selected method, if
158
  \code{\link{MethodDefinition-class}} object, the selected method, if
165
  a unique selection exists.
159
  a unique selection exists.
Line 189... Line 183...
189
  interface developed more recently than the reference.  For a
183
  interface developed more recently than the reference.  For a
190
  discussion of details and ongoing development, see the web page
184
  discussion of details and ongoing development, see the web page
191
  \url{http://developer.r-project.org/methodsPackage.html} and the
185
  \url{http://developer.r-project.org/methodsPackage.html} and the
192
  pointers from that page.
186
  pointers from that page.
193
}
187
}
-
 
188
\seealso{\code{\link{GenericFunctions}}}
194
\examples{
189
\examples{
195
setGeneric("testFun", function(x)standardGeneric("testFun"))
190
setGeneric("testFun", function(x)standardGeneric("testFun"))
196
setMethod("testFun", "numeric", function(x)x+1)
191
setMethod("testFun", "numeric", function(x)x+1)
197
hasMethod("testFun", "numeric")
192
hasMethod("testFun", "numeric")
198
\dontrun{[1] TRUE}
193
\dontrun{[1] TRUE}
Line 203... Line 198...
203
hasMethod("testFun") # default method
198
hasMethod("testFun") # default method
204
\dontrun{[1] FALSE}
199
\dontrun{[1] FALSE}
205
hasMethod("testFun", "ANY")
200
hasMethod("testFun", "ANY")
206
\dontrun{[1] FALSE}
201
\dontrun{[1] FALSE}
207
\dontshow{
202
\dontshow{
208
stopifnot(isGeneric("testFun"))
203
stopifnot(isGeneric("testFun"),
209
stopifnot(hasMethod("testFun", "numeric"))
204
	  hasMethod("testFun", "numeric"),
210
stopifnot(hasMethod("testFun", "integer"))
205
	  hasMethod("testFun", "integer"),
211
stopifnot(!existsMethod("testFun", "integer"))
206
	  !existsMethod("testFun", "integer"),
212
stopifnot(!hasMethod("testFun"))
207
	  !hasMethod("testFun"),
213
stopifnot(!hasMethod("testFun", "ANY"))
208
	  !hasMethod("testFun", "ANY") )
214
removeGeneric("testFun")
209
removeGeneric("testFun")
215
}
210
}
216
}
211
}
217
\keyword{programming}
212
\keyword{programming}
218
\keyword{classes}
213
\keyword{classes}