Skip to content

Commit

Permalink
always use withAutoprint (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Jul 10, 2024
1 parent 7c12664 commit fb87b7f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions R/rd-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/rd-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down

0 comments on commit fb87b7f

Please sign in to comment.