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



我已经创建了自己的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")
#' }

或:

您可以不直接在文档中包含示例,而是可以 将它们放在单独的文件中并使用@example 路径/相对/到/包/根以将它们插入到文档中。 (请注意,此处的@example标签没有"s"。

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

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

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

dontrun{} 应该只在示例确实无法执行时才使用(例如,因为缺少其他软件,缺少 API 键,...由用户。 这就是为什么在 \dontrun{} 中包装示例的原因 添加注释("# Not run:")作为对用户的警告。请 如果示例在 5 秒内可执行,请解开它们

已解决。如果有人仍在寻找解决方案,我只是遇到了同样的问题并修复了。问题出在函数名称上 - 不要使用点来分隔单词,使用下划线。

当roxygenize创建文档文件时,它可能会添加如下内容:

method{extract}{sentiments}(df)

所以它会自动分隔单词。相反,如果使用下划线,则由于某种原因,文档文件将不包含 \method 部分。这纠正了我的问题。

注意:我的其他函数仍然使用点而不是下划线 - 但它们不知何故没有导致 roxygenize 在 man 文件夹的 rd 文档中创建上面的 \method 行。

对我来说

,这个问题真是空白太多了!

错:

#' dontrun {

#' dontrun{

最新更新