Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check()-ing package failed because of @example

Tags:

package

r

cran

I have created my own R package that is supposed to be submited to CRAN. Documentation and other stuff is generated with Roxygen from the following R file:

#' 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...

But something is wrong with @example section, because when i run check() command, I got the following result:

* 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)

What is wrong? After removing the @example, check() command is ok, but I heard that, this type of error is a serious problem with package and removing the @example section is not solution.

like image 256
user1890078 Avatar asked Oct 31 '22 10:10

user1890078


1 Answers

One solution to similar errors is to add example in a dontrun chunk:

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

or:

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’.)

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

Also if using document() and having manually edited NAMESPACE, it will not be re-generated.

EDIT: Cran reviewer discourages use of dontrun: (email)

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.

like image 128
Ferroao Avatar answered Nov 09 '22 05:11

Ferroao