如何在R包文档中使用或转义特殊字符@?
Ah, I've run into this exact issue before! The @ character is a special tag marker in Roxygen2, so even when it's inside a URL string in your examples, Roxygen tries to parse it as a documentation tag, leading to those annoying syntax errors.
Here are two solid ways to fix this:
1. Double Up the @ (@@)
The easiest and most reliable fix is to replace the single @ with two @ signs (@@). Roxygen2 will automatically convert this pair into a single literal @ in the final documentation, and it works everywhere in your roxygen comments—not just examples.
Your corrected example code would look like this:
#' @importFrom utils file.edit #' #' @export #' #' @examples #' library(dplyr) #' medium("https://medium.com/@@data_datum/ggplot2-or-how-to-make-fancy-graphics-with-r-fabae7fc16d4")
2. Use a Single Backslash (\@) in Code Blocks
If you prefer, in code sections like @examples, you can prepend the @ with a single backslash (\@). This tells Roxygen to treat the @ as a regular character instead of a tag.
Here's how that would look:
#' @importFrom utils file.edit #' #' @export #' #' @examples #' library(dplyr) #' medium("https://medium.com/\@data_datum/ggplot2-or-how-to-make-fancy-graphics-with-r-fabae7fc16d4")
Why Your Multiple Backslash Attempts Didn't Work
You tried single, double, triple, and quadruple backslashes, but that's overcomplicating things. Roxygen doesn't require escaping the backslash itself in comment blocks—using just one \@ is enough. Extra backslashes would end up as literal backslashes in your URL, which isn't what you want.
Content of the question originates from Stack Exchange, asked by stevec

