Skip to content

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

escape_examples(x)

Examples

# In examples we automatically escape Rd comments (%):
100 %% 30
#> [1] 10
# even if they are in strings
"50%"
#> [1] "50%"

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

# other string escapes are left as is
"\""
#> [1] "\""
"\n"
#> [1] "\n"

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

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