r - 由于@example,Check()-ing 包失败

标签 r package cran

我已经创建了我自己的 R 包,应该提交给 CRAN。使用 Roxygen 从以下 R 文件生成文档和其他内容:

#' Measure stability of features in time
#'
#' This function computes IGR for each sliding window of given size. 
#' @param data A matrix or a data frame with attribute-value structure (attributes in columns and samples in rows). Only label attribute can be named "label".
#' @param time A column index or column name in the data, which defines sample ordering. The attribute must be numeric.
#' @param label A column index or column name in the data, which holds the target value.
#' @param window_size_ratio A ratio of the count of samples in the sliding window to the count of samples in the data. The default is 0.3.
#' @param window_count Count of the used sliding windows. The default is 10. 
#' @return igr - A matrix with the Information Gain Ratio for each attribute (in the column) in the given sliding window (in the row).
#'         The column names are inherited from the data. Sliding windows are sorted by time ascendingly. 
#'          sample_count - A vector with the count of samples in each sliding window.
#'          or
#'          NA - In case of error 
#' @import caret ggplot2
#' @examples 
#'  result <- time.igr(ggplot2::mpg, 'year', 'class')






time.igr <- function(data, time, label, window_size_ratio=0.3, window_count=10) {

    # Initialization

    sample_cnt = nrow(data)
    att_cnt = ncol(data)

and so on...

但是@example 部分有问题,因为当我运行 check() 命令时,我得到以下结果:
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd \usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking examples ... ERROR
Running examples in 'prediction.stability.in.time-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: time.igr
> ### Title: Measure stability of features in time
> ### Aliases: time.igr
> 
> ### ** Examples
> 
>  result <- time.igr(ggplot2::mpg, 'year', 'class')
Error: could not find function "time.igr"
Execution halted
* checking PDF version of manual ... OK
* DONE

Status: 1 ERROR
See
  'C:/Users/ondrnovy/AppData/Local/Temp/RtmpoHMRTD/prediction.stability.in.time.Rcheck/00check.log'
for details.

Error: Command failed (1)

怎么了?删除@example 后,check() 命令就可以了,但我听说,这种类型的错误是包的严重问题,删除@example 部分不是解决方案。

最佳答案

类似错误的一种解决方案是在 dontrun 块中添加示例:

#' @examples
#' \dontrun{
#' sum("a")
#' }

或者:

Instead of including examples directly in the documentation, you can put them in separate files and use @example path/relative/to/package/root to insert them into the documentation. (Note that the @example tag here has no ‘s’.)



来源:http://r-pkgs.had.co.nz/man.html#man-functions

另外如果使用 document()并已手动编辑 NAMESPACE ,它不会重新生成。

编辑:Cran 审阅者不鼓励使用 dontrun:(电子邮件)

dontrun{} should be only used if the example really cannot be executed (e.g. because of missing additional software, missing API keys, ...) by the user. That's why wrapping examples in \dontrun{} adds the comment ("# Not run:") as a warning for the user. Please unwrap the examples if they are executable in < 5 sec, or create additionally small toy examples to allow automatic testing (then replace \dontrun with \donttest). You could also replace \dontrun{} with \donttest, but it would be preferable to have automatic checks for functions.

关于r - 由于@example,Check()-ing 包失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34973844/

相关文章:

r - 如何使用 dev.new() 在 knitr 小插图中显示图?

linux - R-Forge 包检查错误。 linux平台上的包依赖

r - 安装多个软件包,因为它们在特定日期存在于 CRAN 上?

R Markdown 内联代码未执行

r - lm() 在 mutate() 中调用

r - 使用 Shiny 的 DT 动态预选行

c# - 在 .Net 中调用命名空间的最佳方法是什么

gcc - golang 在使用和不使用 cgo 进行构建时使用的汇编程序

python - 让 Rpy2 与 rgdal 一起工作以获取空间子集点

python - 在python中导入文件