R 中 roxygen 文档中的转义引号
我的文档中有一个 R 函数示例,需要转义引号:(
#' @examples msearch("published_in:\"Journal of Ecology\"")
或者至少我不够聪明,无法避免转义引号)。虽然此命令在 R 中可以正常工作,但 roxygenize/document 函数会将其转换为
msearch("published_in:\\"Journal of Ecology\\"")
.Rd 文件中的双重转义。我该如何解决这个问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所看到的,roxygen 文档块中的以下行
被转换为 *.Rd 文件中的
以下行,并在各种< strong>帮助文件格式
我猜这就是您在最终产品中真正想要的。正如它在许多其他方面所做的那样,
roxygen
正在简化编写帮助文件的过程 - 在本例中,通过让您在您希望的位置键入\
实际出现。它通过转义\
来实现这一点(否则您必须这样做),这就是您在查看*.Rd
文件时看到的内容。As you've seen, the following line in an roxygen documentation block
is converted to this in an *.Rd file
on its way to becoming the following, in the various help file formats
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.你需要问自己这是否真的是一个问题。在 R-help 中,经常提出一个关于为什么这是真的的问题:
并且提出了更多关于如何删除不需要的“\”的问题......实际上并不存在。
如果您想在字符串内使用双引号,那么也许可以在它的两侧使用单引号?或者考虑 tidy.source 函数: http://finzi .psych.upenn.edu/R/library/formatR/html/tidy.source.html
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:
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