简体   繁体   中英

How do you escape “}” using 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

在此输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM