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

时间:2016-01-24 08:54:01

标签: r package cran

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

#' 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部分不是解决方案。

1 个答案:

答案 0 :(得分:0)

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

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

或:

  

您可以直接在文档中添加示例,而不必在示例中添加示例   将它们放在单独的文件中并使用@example   将它们插入文档的路径/相对/到/包/根目录。   (请注意,这里的@example标记没有's'。)

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

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