R/getDispatchMethodS3.R

###########################################################################/**
# @RdocDefault getDispatchMethodS3
#
# @title "Gets the S3 method that a generic function would call"
#
# \description{
#  @get "title" according to an S3 @see "base::class" @vector.
# }
#
# @synopsis
#
# \arguments{
#   \item{methodName}{A @character string specifying the name of a
#     generic function.}
#   \item{classNames}{A @character @vector of @see "base::class" names.}
#   \item{...}{Not used.}
# }
#
# \value{
#   Returns a @function, or throws an exception if not found.
# }
#
# \seealso{
#   @see "findDispatchMethodsS3".
# }
#
# @author
#
# @keyword programming
# @keyword methods
# @keyword internal
#*/###########################################################################
setMethodS3("getDispatchMethodS3", "default", function(methodName, classNames, ...) {
  res <- findDispatchMethodsS3(methodName, classNames, firstOnly=TRUE, ...)
  if (length(res) == 0) {
    stop(sprintf("No method %s() for this class structure: %s", methodName, paste(classNames, collapse=", ")))
  }

  res[[1]]$fcn
}, private=TRUE)

Try the R.methodsS3 package in your browser

Any scripts or data that you put into this service are public.

R.methodsS3 documentation built on June 14, 2022, 1:06 a.m.