Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using unbalanced brace in Roxygen/Rd code example

Tags:

r

roxygen2

rd

The following MWE fails to compile (via devtools::document()):

#' MWE
#'
#' @examples
#' format('{}') # Works
#' format('{')  # Nope
#' format('\{') # Nope
#' format('\\{')# Nope
format = function (str) {}

Regardless of which of the “Nope” lines I include, it always fails with the error

Failure in roxygen block beginning mwe.r:1
Mismatched braces …

According to my reading of the Rd documentation, this should work by escaping the brace. However, as shown above, this does not work. Am I doing something wrong or is this a bug in Roxygen?

One hint that this might be a Roxygen bug is the full error message when I use the single-escaped version (format('\{')):

Mismatched braces: "@example format('{}') # Works format('\\{') # Nope"

Note that the single backslash in the input has been doubled in the output.

like image 647
Konrad Rudolph Avatar asked Oct 08 '15 16:10

Konrad Rudolph


1 Answers

Not sure when this was fixed but with roxygen2 version 6.0.1 this issue seems resolved.

devtools::document() on the MWE produces a valid Rd:

\examples{
format('{}') 
format('{')  
format('\\{') 
format('\\\\{')
}
like image 57
GGamba Avatar answered Oct 19 '22 02:10

GGamba