Exporting an S3 Method for more than class (with multiple assignment)

315 views Asked by At

I have a package with an S3 generic and several methods. I'm using the same function to handle more than one class and hence I'm assigning the same function to more than one name. The specific issue I have is that roxygen2 doesn't realize that both variables are bound to an S3method, and without including an @S3method directive, it fails to export some of the S3 methods. However, this results in a deprecation warning ("@S3method is deprecated. Please use @export instead")

The following (contrived) little example illustrates the issue:

#' The size of an object.
#' The size of an object
#' 
#' @export
size  <- function(x) UseMethod('size')

#' @export
size.default  <-  function(x) "I dunno" 

#' @export
#' @S3method size matrix
size.data.frame  <-  
size.matrix  <-  function(x) prod(dim(x))

#' @export
#' @S3method size character
size.factor  <-  
size.character  <-  function(x) length(x)

#' @export
#' @S3method size integer
size.double  <-  
size.integer  <-  function(x) sum(x)

I can't figure out a way to export the matrix, character, and integer methods without using the deprecated @S3method directives. Is there a way to export these methods without using a deprecated directive?

Thanks!

1

There are 1 answers

2
hadley On BEST ANSWER

The easiest way would be to use two lines:

#' @export
size.matrix  <-  function(x) prod(dim(x))
#' @export
size.data.frame  <-  size.matrix