Question

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?

Was it helpful?

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.

OTHER TIPS

You need to ask yourself whether that truly represents a problem. In R-help there is a frequent question raised about why this is TRUE:

nchar("\n") == 1

And further questions raised about how to remove an unwanted "\" .... which really isn't there.

If you want to use double quotes inside a string, then perhaps use single quotes to flank it? Or consider the tidy.source function: http://finzi.psych.upenn.edu/R/library/formatR/html/tidy.source.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top