R package - @example function cannot be checked if the function is not exported

I am developing a custom R package with RStudio, documented using roxygen2.

Please consider this feature:

#' Get "test"
#'
#' @return String
#' @export
#'
#' @examples getTest()
getTest <- function() {
  return("test")
}

If I started R CMD checkwith the function documentation written as described above, everything is in order, it checkis transmitted with success.

Now, if I remove @export(because I do not want this function to be visible from outside the package), I get the following error:

* checking examples ... ERROR
Running examples in 'MyPackageName-Ex.R' failed
The error most likely occurred in:

> ### Name: getTest
> ### Title: Get "test"
> ### Aliases: getTest
> 
> ### ** Examples
> 
> getTest()
Error: could not find function "getTest"
Execution halted

It seems that checking the functions from @examplesis performed from outside the package !?

How to check examples of non-exported function?

+4
source share
1 answer

@Roland, , , , , , 6 . check(), , . - R .

, triple-column :::. :

 ##' Drop specified dimension from an array
 ##'
 ##' Like drop(x) but only dropping specified dimensions.
 ##' There is no testing that the specified dimensions are actually     singletons.
 ##' @param x array of at least d dimensions
 ##' @param d dimension(s) to drop
 ##' @return array x
 ##' @examples
 ##' x = array(1:4, dim=c(1, 2, 1, 2))
 ##' dx = MAST:::Drop(x, 1)
 ##' stopifnot(all(dim(dx)==c(2,1,2)))
 ##' 
    Drop <- function(x, d){
        dim(x) <- dim(x)[-d]
        x
    }
+1

Source: https://habr.com/ru/post/1619321/


All Articles