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

Charles Determan cdetermanjr at gmail.com
Mon Jun 26 18:28:29 CEST 2017


Greetings R users,

I was wondering how others are exporting S3 methods in their packages when
the generic is in 'base'.  For example, let's say I want to export a new
pmax method.  The only way I have found to get this to work is by
redefining the function with 'UseMethod' and setting the default method.

#' @export
pmax <- function(...){ UseMethod("pmax") }
#' @export
pmax.default <- function(..., na.rm=FALSE){ base::pmax(..., na.rm=FALSE) }

setClass("myclass")

#' @export
pmax.myclass <- function(..., na.rm = FALSE){
    print('myclass pmax!')
}

Although this works, I get the 'warning'

The following objects are masked from 'package:base':

    pmax


I would like the package build and loading to be as clean as possible but
if this is acceptable and not considered a problem I will let it go.  It
just seems odd that one would to redefine a the generic when in states in
the docs for 'pmax' that it will also work on classed S3 objects but
perhaps I am reading this incorrectly.

Thanks,
Charles

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list