escape_examples: Escape examples

Description Usage Examples

View source: R/rd-examples.R

Description

This documentation topic is used primarily for testing and to record our understanding of the \example{} escaping rules. See https://developer.r-project.org/parseRd.pdf for the details provided by R core.

Usage

1

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# In examples we automatically escape Rd comments (%):
100 %% 30
# even if they are in strings
"50%"

# and \ and \v inside of strings and symbols
"\v" # vertical tab
"\\"
# but not comments: \l \v

# other string escapes are left as is
"\""
"\n"

# Otherwise, backslashes and parentheses are left as is. This
# means that you need to escape unbalanced parentheses, which typically only
# occur in \dontshow{}:

print("Hello")


# You also need to escape backslashes in infix operators and comments
# (this is generally rare)
`%\\%` <- function(x, y) x + y
10 %\% 20
# \\ (renders as two backslashes)

Example output

[1] 10
[1] "50%"
[1] "\v"
[1] "\\"
[1] "\""
[1] "\n"
[1] "Hello"
[1] 30

roxygen2 documentation built on Sept. 8, 2021, 9:08 a.m.