Using unbalanced brace in Roxygen/Rd code example
Asked Answered
F

1

7

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.

Freemon answered 8/10, 2015 at 16:18 Comment(5)
@Josh Your (now deleted) answer makes this compile but — as you may have noticed, considering the deletion — it results in a broken Rd file that will show errors when attempting to display the help in R. So can we conclude that this is a roxygen bug?Freemon
It sure looks like a bug. I deleted because I realized (duh) that the extra right brace was just being used to close the \examples{} sectionAdelaidaadelaide
Well, bug reported at github.com/klutometis/roxygen/issues/393Freemon
maybe you can close the question now ?Frayda
@KarlForner Actually if you look at the bug report you’ll see that even with the bug fixed (at least ostensibly), the problem persists. I’m unsure whether this is a bug or whether I’m doing something wrong. At any rate, the original question has evolved by remains essentially unanswered.Freemon
A
1

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('\\\\{')
}
Alysonalysoun answered 8/2, 2017 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.