[R-pkg-devel] Printing examples conditionally on another package in Suggests

Zhian Kamvar zk@mv@r @ending from gm@il@com
Fri Aug 10 12:18:12 CEST 2018


I know it's good practice to use

if (require("some_package")) {
  # some code that needs some_package

In R examples that needs a package listed in Suggests.

The problem with this approach is that if there are any print statements
within this structure, then they only get printed after the braces and not
after the lines like so:

if (TRUE) {
#> [1] "Hi"
#> [1] "Hello"
#> [1] "Goodbye"

The only way I can think of circumventing this is by replacing the if
statement with a stopifnot statement:

# some code that needs some_package

But, I'm not sure if that's okay to do in a function example. Does anyone
have any ideas or suggestions on how to help with this kind of thing?


	[[alternative HTML version deleted]]

More information about the R-package-devel mailing list