Skip to content
Prev 1709 / 12125 Next

[R-pkg-devel] Exporting S3 methods for base generics

Hi Charles,

if a generic exists already in the base, you only have to export the actual
S3 method. Your problem is that base::pmax() is not a generic S3 function.
So R gives you the correct warning: the S3 generic in your package will
always mask the base pmax function. And that's not really a problem,
especially since you ensured the base functionality with your default
method.

If you want to avoid that warning, use S4.

#' @rdname
setGeneric("pmax")

#' @rdname pmax
#' @method pmax myclass
#' @export
setMethod("pmax",
                  "myclass",
                  function(...){
                     # do some stuff
})

More information on how to deal with dots can be found on the help page
?dotsMethods.

If you have a generic in the base package (eg plot is such one), you only
define the method and use:

#' @export
plot.myclass <- function(x, y, ...){
   # do some more stuff
}

Cheers
Joris



On Mon, Jun 26, 2017 at 6:28 PM, Charles Determan <cdetermanjr at gmail.com>
wrote: