我被要求更新我的软件包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 的 devel 版本运行它时,我收到代码不匹配警告,因为用法不允许 ...,即
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:
...
任何帮助/建议表示赞赏。
下面给出了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))
}
}