You can use \donttest{}
to your example. The snippet will be provided in your documentation, but won't get tested with the R CMD Check.
For more info --> ?example
#' @example
\donttest{
2^2
}
This 2^2 won't get run when you run devtools::check()
EDIT
Per the latest release notes or NEWS for R 4.0.0, examples within \donttest{}
will now be tested by default. This can, however, be overridden by setting environment variable _R_CHECK_DONTTEST_EXAMPLES_
to FALSE
.
R CMD check --as-cran now runs \donttest examples (which are run by example()) instead of instructing the tester to do so. This can be temporarily circumvented during development by setting environment variable R_CHECK_DONTTEST_EXAMPLES to a false value.
According to this GitHub issues discussion (credited here), Hadley Wickham noted that
Generally, now if you don't want to run tests on CRAN \dontrun{} is more likely to work, but using \dontrun{} may cause initial submission to fail.
There are other ways as well that will let you continue to use donttest{}
, refer the aforementioned discussions for the workarounds.
?example
and Writing R Extensions – Flashgun