Roxygen2: Using @example path/to/example.R fails for R6 classes

Created on 12 Oct 2020  路  2Comments  路  Source: r-lib/roxygen2

My reprex package jranke:R6ExampleTest fails like this:

LANG=C Rscript -e 'roxygen2::roxygenize()'
Loading R6ExampleTest
Loading required package: R6
Error in file.path(base_path, x$val) : 
  cannot coerce type 'closure' to vector of type 'character'
Calls: <Anonymous> ... roxy_tag_rd -> roxy_tag_rd.roxy_tag_example -> file.path
Execution halted

I believe the cause of this bug is the same as for #1151, the character string base_path is not found, only the function base_path() as defined in https://github.com/r-lib/roxygen2/blob/master/R/collate.R#L71

bug R6

Most helpful comment

I had a similar issue which seemed to be circumvented by separating the @example into its own roxygen block:

#' My Class.
#'
#' @name MyClass
#' @example path/to/example.R
NULL

#' @rdname MyClass
#' @export
MyClass <- R6::R6Class(...)

All 2 comments

I had a similar issue which seemed to be circumvented by separating the @example into its own roxygen block:

#' My Class.
#'
#' @name MyClass
#' @example path/to/example.R
NULL

#' @rdname MyClass
#' @export
MyClass <- R6::R6Class(...)

Thanks for the workaround.

Was this page helpful?
0 / 5 - 0 ratings