Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you escape "}" using roxygen2?

Tags:

r

roxygen2

I'm documenting a function using roxygen2 with an @example.

The example has a string that contains a } symbol.

#' ...
#' @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.

like image 527
SymbolixAU Avatar asked May 21 '16 08:05

SymbolixAU


1 Answers

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.

like image 198
hrbrmstr Avatar answered Oct 21 '22 00:10

hrbrmstr