Skip to content

Commit 2b1eeac

Browse files
Merge pull request #833 from lorenzwalthert/issue-826
- Two error on unsupported {roxygen2} `@examplesIf` condition (#833).
2 parents 85f41ef + f9b9523 commit 2b1eeac

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
* Don't break line before comments in pipes (#822).
88

9-
* Ordinary comments (starting with `#`) within a roxygen code example block
9+
* Ordinary comments (starting with `#`) that break a roxygen code example block
1010
(starting with `#'`) are now recognized and preserved (#830).
1111

12+
* `@examplesIf` conditions longer than one line after styling throw an error for
13+
compatibility with {roxygen2} (#833).
14+
1215
* R Markdown chunk headers are no longer required to be parsable R code (#832).
1316

1417
* Break the line between `%>%` and `{` inside and outside function calls (#825).

R/roxygen-examples.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@ style_roxygen_code_example <- function(example, transformers, base_indention) {
2525
style_roxygen_code_example_one <- function(example_one, transformers, base_indention) {
2626
bare <- parse_roxygen(example_one)
2727
one_dont <- split(bare$text, factor(cumsum(bare$text %in% dont_keywords())))
28-
map(one_dont, style_roxygen_code_example_segment,
28+
unmasked <- map(one_dont, style_roxygen_code_example_segment,
2929
transformers = transformers,
3030
base_indention = base_indention
3131
) %>%
32-
flatten_chr() %>%
32+
flatten_chr()
33+
if (bare$example_type == "examplesIf") {
34+
with_handlers(
35+
parse_text(unmasked[1]),
36+
error = function(e) {
37+
abort(paste0(
38+
"Could not style condition in `@examplesIf` because it would result ",
39+
"in multi-line condition, which is currently not supported in ",
40+
"{roxygen2} (see https://github.com/r-lib/roxygen2/issues/1242)."
41+
))
42+
}
43+
)
44+
}
45+
unmasked %>%
3346
add_roxygen_mask(example_one, bare$example_type)
3447
}
3548

tests/testthat/test-roxygen-examples-complete.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ test_that("analogous to test-roxygen-examples-complete", {
117117
transformer = style_text
118118
), NA)
119119

120-
expect_warning(test_collection(
120+
expect_error(test_collection(
121121
"roxygen-examples-complete", "^23",
122122
transformer = style_text
123-
), NA)
123+
), "issues/1242")
124124

125125
expect_warning(test_collection(
126126
"roxygen-examples-complete", "^24",

0 commit comments

Comments
 (0)