Yes, if (interactive()) { ... }
will not run on pkgdown by default, at least not with pkgdown::build_site()
.
Another alternative is the @examplesIf
tag if you are using roxygen2. With that you can write the exact condition you want the example to run.
EDIT: there are about a thousand examples for the @examplesIf
tag on CRAN: https://github.com/search?q=org%3Acran%20%40examplesIf&type=code
E.g. to only run the examples when not on CRAN, always except for R CMD check
, when the computer is online, when some packages are installed, only on Windows, etc.
The good thing about it is that the end user will just see the example code, without any boilerplate at all, but you can still finetune when the examples should be be running, and when they should not.