题
我用Roxygen生成我正在开发包的Rd文件,但我有一些问题,使用默认参数设置功能“\n'
,e.g:
lineCount <- function(text, sep='\n') {
...
}
哪些目的是计数新行('\n'
)字符串中的字符。
问题是在于R CMD检验给出关于一个警告:
Codoc mismatches from documentation object 'lineCount':
lineCount
Code: function(text, sep = "\n")
Docs: function(text, sep = " ")
Mismatches in argument default values:
Name: 'sep' Code: "\n" Docs: " "
这个问题在我看来,因写入到RD文件(写入通过cat()
标准LaTeX文件总是需要为某些目的的双转义字符,例如:\\newline
- 因为我经历)。
如果我把额外的反斜线分离,如:
lineCount <- function(text, sep='\\n') {
...
}
在问题仍然presists,如在它看起来像'\\n'
,的代码,但在该文档(Rd文件),它看起来'\n'
。
有没有我的问题的一个简单的解决方案?可能是在Roxygen一个额外的标签,它可以定义如何将功能的PARAMS写入路文件? 如果问对不起太明显的一个问题,但我谷歌-ING一段时间后消失。
历史: http://permalink.gmane.org/gmane。 comp.lang.r.roxygen / 24
<强>更新强>:使用 roxygen2 一>!
解决方案
我也遇到了太多逃脱问题“和消失\ t最后我改变roxygen的Rd2.R的parse.formals
功能如下:
parse.formals <- function(partitum) {
formals <- partitum$formals
if (!is.null(formals)) {
formals <- lapply(formals, trim)
formals <- lapply(formals, paste, collapse=" ")
name.defaults <- zip.c(names(formals), formals)
args <-
do.call(paste, c(Map(function(name.default) {
name <- car(name.default)
default <- cadr(name.default)
if (! is.character (default)) { # too much escaped.
# Not sure when escaping is needed.
# param = c ("x", "y", "z") works now
default <- gsubfn("\"(.*)\"",
function(x)
sprintf("\"%s\"", gsub("\"", "\\\\\"", x)),
as.character(default))
}
default <- gsub ("\t", "\\\\t", default) # the tabs and newlines are already
default <- gsub ("\n", "\\\\n", default) # tab and newline here.
if (is.null.string(default))
name
else
sprintf('%s=%s', name, default)
},
name.defaults),
sep=', '))
append.Rd(usageTag(parse.function.name(partitum), args))
}
}
希望帮助并不会破坏任何东西。
其他提示
我过这个问题也来了,即我有分裂=“\ +”和分裂=“\ |”在各种功能。
在.Rd文件实际上也表示这些作为分裂=“\ +”和分裂=“\ |”,但任何然后中的R CMD支票读取.Rd文件把它们变成分裂=“+”和分裂=“\ |”,并引起了错误。
如果该.Rd档案发生分裂= “\\ +” 和分裂= “\\ |”它将然后得到正确读取。
我的解决办法是在与.Rd文件/人/目录下运行这个,只是[R CMD前检查:
的perl -e 'S /( “\\\ |”)/ “\\\\\ |”/克;' -pi $(找到BioGeoBEARS /人型的F)
的perl -e 'S /( “\\ +”)/ “\\\\ +”/克;' -pi $(找到BioGeoBEARS /人型的F)
采取了一些试验和错误的,但它的作品!
干杯! 尼克
我有同样的问题。我结束向上通过从与@usage源代码roxygen产生重写预设使用领域。例如。将R源文件包含
#' @usage sourceall(dir = getwd(), pattern = ".*\\\\.R", ...)
sourceall <- function( dir=getwd(), pattern=".*\\.R", ... )
{
blah blah
}
我遇到类似问题roxygen2 V6.0.1。
# this caused errors in R CMD check (non-ASCII chars)
f <- function(x, y, chr = "\u279B")
# this was ok
f <- function(x, y, chr = intToUtf8(0x279B))
在你的情况下,换行字符,也应该工作:
lineCount <- function(text, sep = intToUtf8(10))
好了,弗兰克•我的评论框转义反斜杠字符!我拒绝添加到疯狂和添加反斜杠逃避perl的代码逸出其中逃脱反冲R中的.Rd文件反斜线的blackslashes。
只需加倍所有反斜杠。
或者HMM的代码标记:
perl -e 's/("\\\\\|")/"\\\\\\\\\|"/g;' -pi $(find BioGeoBEARS/man -type f)
perl -e 's/("\\\\\+")/"\\\\\\\\\+"/g;' -pi $(find BioGeoBEARS/man -type f)
是啊,这是很好的。