ROxygen转Rd时如何避免方括号被转换为\link?
解决ROxygen文档中正则表达式方括号被误解析为链接的问题
ROxygen会将正则表达式里的[和]误识别为链接语法([链接文本]),导致文档生成时出现错误的\link{}标记。以下是两种可行的解决方法:
方法1:用
\verb{}包裹正则表达式
把正则放在\verb{}中,ROxygen会将其视为纯文本,不会解析方括号。修改后的ROxygen代码如下:#' \item{strict:}{Performs checks like with \dQuote{unique} and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions. #' As regular expression, this is \dQuote{\verb{^[.]*[a-zA-Z]+[a-zA-Z0-9._]*$}}.}方法2:使用三重反斜杠转义方括号
在R的字符串中,反斜杠需要转义,因此要让ROxygen识别出转义的方括号,需要在方括号前写三个反斜杠(\\\[)。这种写法可读性较差,仅作为备选:#' \item{strict:}{Performs checks like with \dQuote{unique} and additionally fails for names with UTF-8 characters and names which do not comply to R's variable name restrictions. #' As regular expression, this is \dQuote{^\\\[.\\\]*\\\[a-zA-Z\\\]+\\\[a-zA-Z0-9._\\\]*$}.}
checkmate包的开发者正是使用第一种方法(\verb{}包裹)来避免此类解析问题,确保文档生成正常。
内容的提问来源于stack exchange,提问作者vorpal
相关产品推荐
相关产品推荐

