【问题标题】:Check()-ing package failed because of @example由于@example,Check()-ing 包失败
【发布时间】:2016-01-24 08:54:00
【问题描述】:

我创建了自己的 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()命令就ok了,但是听说这种错误是package的严重问题,去掉@example部分不是解决办法。

【问题讨论】:

  • 错误信息很清楚。从您的代码中,roxygen cmets 中缺少 @export 部分,因此该函数未导出,R 找不到它。
  • 嗯,实际上并不那么明显,因为在我的情况下,无论如何默认情况下名称都是导出的。仅当您以某种方式添加 roxygen 示例时才会发生这种情况。我想赞成这个答案,但它隐藏在评论中。
  • 我也有同样的问题。如果我以交互方式检查它工作正常,但在命令行上失败。一切都被导出。这里有消息吗?

标签: r package cran


【解决方案1】:

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

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

或:

除了在文档中直接包含示例,您还可以 将它们放在单独的文件中并使用@example path/relative/to/package/root 将它们插入到文档中。 (注意这里的@example 标签没有's'。)

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

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

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

dontrun{} 仅在示例确实无法执行时使用(例如,由于缺少其他软件、缺少 API 键,...)由用户。这就是为什么在 \dontrun{} 中包装示例 添加注释(“# Not run:”)作为对用户的警告。请 如果示例可以在

【讨论】:

    猜你喜欢
    • 2017-04-05
    • 2014-02-17
    • 2014-11-19
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-06-21
    • 1970-01-01
    相关资源
    最近更新 更多