Search code examples
rroxygen2

R 3.4.0 median methods and roxygen2


I have been asked to update my package Bolstad so that the definition of my S3 median method agrees with the new median generic in R 3.4.0. This means is needs to be able to deal with ... - That is fine, but I also need it to work with roxygen2. Here is my function definition etc.:

#' Median generic
#' 
#' @param x an object.
#' @param na.rm Ideally if \code{TRUE} then missing values will be removed, but not currently used.

#' @param \ldots [>=R3.4.0 only] Not currently used.
#' @details If \code{x} is an object of class \code{Bolstad} then the posterior 
#'   median of the parameter of interest will be calculated.
#' @author James Curran
#' @method median Bolstad
#' @export
median.Bolstad =
if(is.na(match("...", names(formals(median))))) {
  function(x, na.rm = FALSE) {
    return(quantile(x, probs = 0.5))
  }
}else{
  function(x, na.rm = FALSE, ...) {
    return(quantile(x, probs = 0.5))
  }
}

This conditional definition seems to compile okay, but when I run it through the devel version of R, I get a code mismatch warning because the usage hasn't allowed for the ..., i.e.

Codoc mismatches from documentation object 'median.Bolstad':
median.Bolstad
  Code: function(x, na.rm = FALSE, ...)
  Docs: function(x, na.rm = FALSE)
  Argument names in code not in docs:
  ...

Any help/advice appreciated.


Solution

  • The solution that has gone up on CRAN is given below (based on something Kurt Hornik sent me). However, it too has a downside in that roxygen2 does not generate a help file for the median function.

    #' Median generic
    #' 
    #' @param x an object.
    #' @param na.rm Ideally if \code{TRUE} then missing values will be removed, but not currently used.
    #' @param ... [>=R3.4.0 only] Not currently used.
    #' @details If \code{x} is an object of class \code{Bolstad} then the posterior 
    #'   median of the parameter of interest will be calculated.
    #' @author James Curran
    #' @method median Bolstad
    if(is.na(match("...", names(formals(median))))) {
      median.Bolstad = function(x, na.rm = FALSE) {
        return(quantile(x, probs = 0.5))
      }
    }else{
      median.Bolstad = function(x, na.rm = FALSE, ...) {
        return(quantile(x, probs = 0.5))
      }
    }