diff --git a/NEWS.md b/NEWS.md index b59d6d6d..4dd2a871 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,9 @@ titles](https://roxygen2.r-lib.org/articles/index-crossref.html) now support Markdown syntax (#1608, @salim-b). +* `@examplesIf` always uses `withAutoprint()` (@MichaelChirico, #1581). The raw Rd + will be cleaner, but such examples will now only run under R>=3.4.0 (2017). + # roxygen2 7.3.2 * `@includeRmd` now additionally sets `options(cli.hyperlink = FALSE)` to make diff --git a/R/rd-examples.R b/R/rd-examples.R index e519b496..62bec1ec 100644 --- a/R/rd-examples.R +++ b/R/rd-examples.R @@ -14,15 +14,11 @@ roxy_tag_parse.roxy_tag_examplesIf <- function(x) { } ) - dontshow <- paste0( - "\\dontshow{if (", - condition, - ") (if (getRversion() >= \"3.4\") withAutoprint else force)(\\{ # examplesIf}" - ) - x$raw <- paste( - c(dontshow, lines[-1], "\\dontshow{\\}) # examplesIf}"), - collapse = "\n" + paste0("\\dontshow{if (", condition, ") withAutoprint(\\{ # examplesIf}"), + lines[-1], + "\\dontshow{\\}) # examplesIf}", + sep = "\n" ) tag_examples(x) diff --git a/tests/testthat/_snaps/rd-examples.md b/tests/testthat/_snaps/rd-examples.md index e497b349..d03f7244 100644 --- a/tests/testthat/_snaps/rd-examples.md +++ b/tests/testthat/_snaps/rd-examples.md @@ -24,10 +24,10 @@ # @examplesIf \examples{ - \dontshow{if (foo::bar()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} + \dontshow{if (foo::bar()) withAutoprint(\{ # examplesIf} maybe-run-this-code \dontshow{\}) # examplesIf} - \dontshow{if (foobar()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} + \dontshow{if (foobar()) withAutoprint(\{ # examplesIf} and-this \dontshow{\}) # examplesIf} }