An error ['\\+' is an unrecognized escape in character string starting “\\+” while creating a R package

五迷三道 提交于 2019-12-03 22:50:02

The offending code comes from the Examples section of one of your help files (which is why it ends up in packageName-Ex.R). To fix it, just escape each of the backslashes in the Examples sections of your *.Rd documentation files with a second backslash. (So, type \\to get \ in the processed help file, and type \\\\ to get \\.)

Unless it's escaped, \ is interpreted as a special character that identifies sectioning and mark-up macros (i.e. commands like \author, \description, \bold, and \ldots). Quoting from Duncan Murdoch's Parsing Rd files (the official manual for this topic):

The backslash \ is used as an escape character: \, \%, { and } remove the special meaning of the second character.

As an example of what this looks like in practice, here is part of $R_SOURCE_HOME/src/library/base/man/grep.Rd, which is processed to create the help file you see when you type ?grep or ?gsub.

## capitalizing
txt <- "a test of capitalizing"
gsub("(\\\\w)(\\\\w*)", "\\\\U\\\\1\\\\L\\\\2", txt, perl=TRUE)
gsub("\\\\b(\\\\w)",    "\\\\U\\\\1",       txt, perl=TRUE)

In the processed help file, it looks like this:

 ## capitalizing
 txt <- "a test of capitalizing"
 gsub("(\\w)(\\w*)", "\\U\\1\\L\\2", txt, perl=TRUE)
 gsub("\\b(\\w)",    "\\U\\1",       txt, perl=TRUE)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!