Search code examples
rdevtoolsroxygen2

Why does `devtools::document()` trip on `setMethod` whose function definition is empty?


Assume I am building an R package with devtools in RStudio.

Assume also I have this R source file with the following code:

#' @param object An object
#' @param data Numeric vector or data.frame
#' @param Fun Function. Default function is \code{sum}
#' @param ... Extra named arguments passed to FUN
#' @rdname myGeneric
#' @export
setGeneric("myGeneric", function(object, data, FUN, ...)
{standardGeneric ("myGeneric")} )

#' @rdname myGeneric
setMethod("myGeneric", c("numeric", "numeric", "function"),
          function(object, data, FUN, ...) {
            return(42)
            }
          )

Now, devtools::document(roclets=c('rd', 'collate', 'namespace')) runs fine except for that warning about the missing name/title:

> devtools::document(roclets=c('rd', 'collate', 'namespace'))
Updating gwasrapidd documentation
Loading gwasrapidd
Writing NAMESPACE
Writing NAMESPACE
Warning message:
myGeneric.Rd is missing name/title. Skipping 

However if I comment that line return(42) inside the function definition like so:

#' @param object An object
#' @param data Numeric vector or data.frame
#' @param Fun Function. Default function is \code{sum}
#' @param ... Extra named arguments passed to FUN
#' @rdname myGeneric
#' @export
setGeneric("myGeneric", function(object, data, FUN, ...)
{standardGeneric ("myGeneric")} )

#' @rdname myGeneric
setMethod("myGeneric", c("numeric", "numeric", "function"),
          function(object, data, FUN, ...) {
            #return(42)
            }
          )

and run again devtools::document(roclets=c('rd', 'collate', 'namespace')) I get now an error:

> devtools::document(roclets=c('rd', 'collate', 'namespace'))
Updating gwasrapidd documentation
Loading gwasrapidd
Error in method_body[[2]] : subscript out of bounds

My question is why? Is it a bug of devtools?

Package versions:

  • devtools_1.13.6
  • roxygen2_6.1.1

Solution

  • It seems this is a bug in roxygen: https://github.com/klutometis/roxygen/issues/843