Search code examples
rroxygenroxygen2

escaping quotations in roxygen documentation in R


I have an R function example in my documentation that needs to escape quotations:

#' @examples msearch("published_in:\"Journal of Ecology\"")

(Or at least I'm not clever enough to avoid escaping the quotation). While this command works correctly in R, the roxygenize/document function converts this to double escapes

  msearch("published_in:\\"Journal of Ecology\\"")

in the .Rd file. How do I get around this?


Solution

  • As you've seen, the following line in an roxygen documentation block

    #' @examples msearch("published_in:\"Journal of Ecology\"")
    

    is converted to this in an *.Rd file

    msearch("published_in:\\"Journal of Ecology\\"")
    

    on its way to becoming the following, in the various help file formats

    msearch("published_in:\"Journal of Ecology\"")
    

    I'm guessing that is what you actually want in the final product. As it does in so many other ways, roxygen is simplifying the process of writing help files -- in this case by letting you type \s where you'd like them to actually appear. It does so by escaping the \s (as you'd otherwise have to do), which is what you saw when you peeked into the *.Rd file.