【问题标题】:R 3.4.0 median methods and roxygen2R 3.4.0 中值方法和 roxygen2
【发布时间】:2017-03-24 00:23:20
【问题描述】:

我被要求更新我的包Bolstad,以便我的 S3 中值方法的定义与 R 3.4.0 中的新中值泛型一致。这意味着需要能够处理... - 这很好,但我也需要它来处理roxygen2。这是我的函数定义等:

#' 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))
  }
}

这个条件定义似乎可以编译,但是当我通过 R 的开发版本运行它时,我收到一个代码不匹配警告,因为该用法不允许...,即

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:
  ...

任何帮助/建议表示赞赏。

【问题讨论】:

  • 你试过@param ...而不是@param \ldots吗?
  • 试过但不幸的是没有任何区别:(
  • 我猜你需要一个合适的函数签名:median.Bolstad <- function(other arguments, ...)
  • @Helix123 确实如此。下面给出了 CRAN 上的解决方案(基于 Kurt Hornik 发给我的东西)。但是,它也有一个缺点,即roxygen2 不会为中值函数生成帮助文件。

标签: r roxygen2


【解决方案1】:

CRAN 上的解决方案如下(基于 Kurt Hornik 发给我的内容)。但是,它也有一个缺点,即roxygen2 不会为中值函数生成帮助文件。

#' 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))
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 2017-10-26
    • 2018-09-16
    • 2017-09-30
    相关资源
    最近更新 更多