How not to run the example with roxygen2?

I'm writing a geocoding function right now, relying on the presence of a Bing Maps key. Obviously, I would prefer not to publish mine, and the examples would not work without it.

How to enable an example for manual launch by users, but not execute it during R CMD check ?

+52
r roxygen2
Aug 20 2018-12-12T00:
source share
4 answers

Use \dontrun{}

 #'@examples #'\dontrun{ #'geocode("3817 Spruce St, Philadelphia, PA 19104") #'geocode("Philadelphia, PA") #'dat <- data.frame(value=runif(3),address=c("3817 Spruce St, Philadelphia, PA 19104","Philadelphia, PA","Neverneverland")) #'geocode(dat) #'} 
+80
Aug 20 2018-12-12T00:
source share

For those using @example path/to/example.R instead of the @examples tag, you can use the \dontrun environment directly in the example.R file. for example

 # example.R \dontrun{ # this is a long running example for(i in seq(1, 1e5)) { lm(mpg ~ wt, data = mtcars) } } # some other shorter example 2 + 2 
+3
Apr 28 '17 at 3:37 on
source share

Ari, I also use roxygen2 (version 4.1.0). The following is the end of my roxygen2 markup in the definition of my function (gctemplate) before the start of the real part.

 #' @examples #' ## List all G-causalities in a VAR system of 5 variables that will be searched in the pattern of 1 #' ## causer (like-independent) variable and 2 like-dependents conditional on 5-(1+2)=2 of the remaining #' ## variable(s) in the system. Variables are assigned to numbers 1 to nvars. #' ## "1 2 5 3 4" in the resulting line of gctemplate is to indicate the #' ## (conditonal, partial, etc.) G-causality from variable 1 to variables 2 and 5 #' ## conditonal on variables 3 and 4. #' # gctemplate(5,1,2) #' ## The number of all G-causalities to be searched in the above pattern. #' #dim(gctemplate(5,1,2))[[1]] #' @importFrom combinat combn #' @export gctemplate <- function(nvars, ncausers, ndependents){ ... 

I know the GSee dontrun method.
In my technique, both comments are a numerical example and the text explaining the numerical example. I use indentation to make the difference between the two; Note that after "#" there is 1 sharp and 2 sharpness. I always use the above technique # # ## # ########################################## # # The user remains on the copy-paste operation whenever he / she wants to check the function. This method, in my opinion, is more parallel to the classical compromise of the programming philosophy.

0
Dec 25 '14 at 19:14
source share

You can use \donttest{} for your example. This snippet will be provided in your documentation, but will not be verified using the R CMD check.

For more information → ?example

 #' @example \donttest{ 2^2 } 

This 2 ^ 2 will not start when devtools::check() run

Check it out yourself before judging. :)

-one
Jul 09 '17 at 15:01
source share



All Articles