Skip to content

Commit 8a34853

Browse files
Merge pull request #512 from lorenzwalthert/fix-roxygen-code-examples
- Deparse Rd to correctly escape characters (#512).
2 parents 063d8f6 + 3966a78 commit 8a34853

File tree

7 files changed

+91
-3
lines changed

7 files changed

+91
-3
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Suggests:
3636
prettycode,
3737
rmarkdown,
3838
rstudioapi (>= 0.7),
39-
testthat
39+
testthat (>= 2.1.0)
4040
VignetteBuilder: knitr
4141
Encoding: UTF-8
4242
LazyData: true

R/roxygen-examples-parse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ parse_roxygen <- function(roxygen) {
1919
textConnection()
2020
parsed <- connection %>%
2121
tools::parse_Rd(fragment = TRUE) %>%
22-
as.character()
22+
as.character(deparse = TRUE)
2323
is_line_break <- parsed[1] == "\n"
2424
close(connection)
2525
c(parsed[1][!is_line_break], parsed[-1])
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#' things
2+
#'
3+
#' @examples
4+
#' call("\\.")
5+
NULL
6+
7+
8+
#' things
9+
#'
10+
#' @examples
11+
#' call("\n")
12+
NULL
13+
14+
#' things
15+
#'
16+
#' @examples
17+
#' call("\n")
18+
#' ano("\\.", further = X)
19+
NULL
20+
21+
22+
#' things
23+
#'
24+
#' @examples
25+
#' call('\n') # FIXME when single quotes are used, the newline is evaluated
26+
#' ano("\\.", further = X)
27+
NULL

tests/testthat/escaping/basic-escape-in_tree

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#' things
2+
#'
3+
#' @examples
4+
#' call("\\.")
5+
NULL
6+
7+
8+
#' things
9+
#'
10+
#' @examples
11+
#' call("\n")
12+
NULL
13+
14+
#' things
15+
#'
16+
#' @examples
17+
#' call("\n")
18+
#' ano("\\.", further = X)
19+
NULL
20+
21+
22+
#' things
23+
#'
24+
#' @examples
25+
#' call("
26+
#' ") # FIXME when single quotes are used, the newline is evaluated
27+
#' ano("\\.", further = X)
28+
NULL

tests/testthat/roxygen-examples-complete/14-pipe-dontrun-out.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
#' ) %>%
1313
#' there()
1414
#' }
15-
#' call("\n", x = 3)
15+
#' call("\\n", x = 3)
1616
#' @export
1717
NULL

tests/testthat/test-escaping.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test_that("escaping of characters works", {
2+
expect_warning(test_collection("escaping",
3+
transformer = style_text,
4+
write_back = TRUE
5+
), "macro '")
6+
})

0 commit comments

Comments
 (0)