5

I am well aware of how to have roxygen not run an example when the code is directly in the roxygen comments. However, some example may be somewhat verbose or you would want you examples compiled in an examples directory. In which case the @example file_path works fine but I can't figure out how to have roxygen not run (i.e. \dontrun) the example file.

This is admitted very similar to this question but the comments show that this problem was not answered.

test.R

# this does not work
#' @title test_fun
#' @example \dontrun{examples/test_example.R}
test <- function(){
    print("hello")
}

# this does
#' @title test
#' @examples 
#' \dontrun{
#' test()
#' }
test <- function(){
    print("hello")
}

test_example.R

test()

How can I get the former approach to work?

Community
  • 1
  • 1
cdeterman
  • 19,630
  • 7
  • 76
  • 100
  • 1
    not sure about this specific question but you can skip all with `--no-examples` – rawr Jul 14 '15 at 18:19
  • @rawr, that will prevent all examples from running when I run R CMD check but I'm pretty certain CRAN would run check without such a flag. I need to explicitly say don't run this example but still have it in the documentation. – cdeterman Jul 15 '15 at 12:47

1 Answers1

3

It seems I'm able to accomplish this by using roxygen2-style comments for the \dontrun{} block in the example file. This gets around the limitation in Michal's answer.

Create an example file that looks like this:

#' \dontrun{
test()
#' }

More reliably, you can wrap your example in an if(interactive()) {} block, which won't be run during checks but allows you to manually run through the example.

Community
  • 1
  • 1
amc
  • 263
  • 3
  • 19