【发布时间】: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示例时才会发生这种情况。我想赞成这个答案,但它隐藏在评论中。 -
我也有同样的问题。如果我以交互方式检查它工作正常,但在命令行上失败。一切都被导出。这里有消息吗?