【问题标题】:Assignment function documentation fails R CMD CHECK赋值函数文档失败 R CMD CHECK
【发布时间】:2012-11-10 12:24:18
【问题描述】:

我在使用 Roxygen 的 checking 分配函数时遇到问题。

这是一个相当简单的例子:

#' Get sp feature IDs
#' @aliases IDs IDs.default IDs.SpatialPolygonsDataFrame IDs<- IDs<-.SpatialPolygonsDataFrame
#' @param x The object to get the IDs from or assign to
#' @param value The character vector to assign to the IDs
#' @param \dots Pass-alongs
#' @author Ari B. Friedman
#' @rdname IDs
IDs <- function(x,...) {
  UseMethod("IDs",x)
}
#' @method IDs default
#' @S3method IDs default
#' @rdname IDs
IDs.default <- function(x,...) {
  stop("Currently only SpatialPolygonsDataFrames are supported.")
}
#' @method IDs SpatialPolygonsDataFrame
#' @S3method IDs SpatialPolygonsDataFrame
#' @rdname IDs
IDs.SpatialPolygonsDataFrame <- function(x,...) {
  vapply(slot(x, "polygons"), function(x) slot(x, "ID"), "")
}

#' Assign sp feature IDs
#' @rdname IDs
"IDs<-" <- function( x, value ) {
  UseMethod("IDs<-",x)
}
#' @method IDs<- SpatialPolygonsDataFrame
#' @S3method IDs<- SpatialPolygonsDataFrame
#' @rdname IDs
"IDs<-.SpatialPolygonsDataFrame" <- function( x, value) {
  spChFIDs(x,value)
}

当我运行check:

* checking for code/documentation mismatches ... WARNING
Codoc mismatches from documentation object 'IDs':
IDs<-
  Code: function(x, value)
  Docs: function(x, value, value)
IDs<-.SpatialPolygonsDataFrame
  Code: function(x, value)
  Docs: function(x, value, value)

我不明白第二个value 来自哪里。我已经尝试消除 @param value 的理论,即 Roxygen 可能会自动为赋值函数创建一个条目,但这并没有消除 (x,value,value) 的定义并产生一个新的警告,抱怨我没有定义 value

这是生成的.Rd 的相关部分:

\usage{
  IDs(x, ...)

  \method{IDs}{default} (x, ...)

  \method{IDs}{SpatialPolygonsDataFrame} (x, ...)

  IDs(x, value) <- value

  \method{IDs}{SpatialPolygonsDataFrame} (x, value) <-
    value
}

我没有看到 check 声称的 (x, value, value) 签名。

这是一个 S3 函数,但它在 S4 对象上运行。我认为这仍然应该使它成为 S3。但如果不是,那可能是我对@S3method 的使用是问题所在。

帮助?

【问题讨论】:

标签: r roxygen2


【解决方案1】:

这是一种相当骇人听闻的方法,但似乎 roxygen 处理此问题的方式暂时仍被破坏(LINK)。但是您可以直接手动将使用部分添加到您的 roxygen cmets 中。

#' Assign sp feature IDs
#' @rdname IDs
#' @usage IDs(x) <- value
"IDs<-" <- function( x, value ) {
    UseMethod("IDs<-",x)
}

#' @method IDs<- SpatialPolygonsDataFrame
#' @S3method IDs<- SpatialPolygonsDataFrame
#' @rdname IDs
#' @usage IDs(x) <- value
"IDs<-.SpatialPolygonsDataFrame" <- function( x, value) {
    spChFIDs(x,value)
}

【讨论】:

    猜你喜欢
    • 2022-08-16
    • 1970-01-01
    • 2021-02-05
    • 2016-12-03
    • 2019-10-23
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    相关资源
    最近更新 更多