SymbolixAU SymbolixAU - 1 month ago 7x
R Question

How do you escape "}" using roxygen2?

I'm documenting a function using

with an

The example has a string that contains a

#' ...
#' @examples
#' \dontrun{
#' ## polyline joining the capital cities of Australian states
#' pl <- "nnseFmpzsZgalNytrXetrG}krKsaif@kivIccvzAvvqfClp~uBlymzA~ocQ}_}iCthxo@srst@"
#' df_polyline <- decodepl(pl)
#' }
#' ...

When built, the documentation for the example is

enter image description here

Where everything after the first
is cutt off.

How do I escape the
so that it is included in the string in the example?

I've tried a backslash
with no luck.

Update - 01 Sep 2016

The official response to my issue from Hadley

Fixing this is quite difficult (as far as I can it will require writing a considerably more complicated Rd parser), and it's a rare occurrence, so realistically this is never going to get high up enough on my to do list to fix it.


TLDR: longer term fix: file an issue.

You "got lucky" this built since you had just enough }'s to get past some Rd installation errors.

I even tried using @example inst/examples/ex.r and putting the code (with the \dontrun{} wrapper since it is supported there) and the same thing happens with that method since the same roxygen parsing/translating code seems to be in play there too.

  • SHORT TERM FIX #1: manually edit the generated Rd file to do the single \} for each of the }. To make this something you don't accidentally overwrite, generate it once, do the fix then de-roxygenize that function until there's a fix.

  • SHORT TERM FIX #2: for that bit of code, the string assignment can happen outside of the \dontrun{} block (which is really what's causing this). Move it out and you can continue with roxygenizing.

  • LONG TERM FIX: file an issue to the above URL.