How do you escape "}" using roxygen2?
Asked Answered
S

1

11

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.

Species answered 21/5, 2016 at 8:23 Comment(0)
F
5

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.

Foin answered 21/5, 2016 at 11:52 Comment(4)
Maybe #3: Replace } in the string by \u007d. Haven't tried it, but will probably work.Casting
I've expanded on #2 and removed \dontrun{ }. The example can happily be run :)Species
@Casting - yes, that appears to work too, thanks. However, I'd like to keep the string 'as-is', so I've also filed an issue.Species
I've updated my question with a response from Hadley - this issue is unlikely to get fixed.Species

© 2022 - 2024 — McMap. All rights reserved.