14

I'm running a CMD check on a package in RStudio, part of which analyses the @examples in the inline Roxygen documentation.

I'm getting this error:

checking examples ... ERROR
Running examples in ‘packagename-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: checkDate
> ### Title: Ensure that a date string is a valid date
> ### Aliases: checkDate
> 
> ### ** Examples
> 
> checkDate("2017-05-06")
Error: could not find function "checkDate"

Within my .R file, the documentation is defined as:

#' Ensure that a date string is a valid date
#'
#' @param dateString A string (eg. "2017-12-04").
#' @return TRUE or FALSE (and a warning if FALSE).
#' @examples
#' checkDate("2017-05-06")
#' checkDate("2017-05-40")

I am using devtools 1.13.2 and roxygen2 6.0.1, both of which I believe to be up-to-date at time of posting.

I have other packages using this same devtools/roxygen2 combination but have never before seen it fail to find a function name in @examples within its scope.

Someone else seems to have experienced something similar as an update to this question, but I can't see that anyone says how to fix it.

Serenthia
  • 1,222
  • 4
  • 22
  • 40

1 Answers1

12

My guess is that you need to #' @export the function in the Roxygen comment, otherwise the function is not exported to the namespace of the package and it cannot be found.

Consistency
  • 2,884
  • 15
  • 23
  • Thanks. Do you know of any way to include examples in the documentation without making the function public? (for other developers of the package) – Serenthia Jun 23 '17 at 15:48
  • EDIT: I guess this isn't necessary - can just include comments. – Serenthia Jun 23 '17 at 15:50
  • 1
    @Serenthia You could try `pkg:::function`, then you don't have to make the function public. – Consistency Jun 23 '17 at 15:51
  • With the `pkg:::function` approach you'll likely receive [a warning, and it may stop the package being accepted on CRAN](https://stackoverflow.com/q/36852140/5977215) – SymbolixAU Dec 02 '17 at 08:37
  • Yes, that is true, could do some trick like `do.call(":::", list(pkgname, functionname)` to overcome this, but it is not recommended anyway... – Consistency Dec 02 '17 at 23:44