在我的包中,我有以下内部函数.batStats()
> .batStats
function(x)
{
wData <- weightsData[rownames(weightsData) %in% x$yearID, ]
wOBA <- .wOBA(x, wData)
wRC <- .wRC(x, wData, wOBA)
stats <- with(x, {
cbind(
PA = { AB + BB + HBP + SH + SF },
TB = assign("TB", { (H - X2B - X3B - HR) + 2 * X2B + 3 * X3B + 4 * HR } ),
AVG = { H/AB },
OBP = { (H + BB + HBP)/(AB + SF + BB + HBP) },
SLG = { TB/AB },
ISO = { (X2B + 2 * X3B + 3 * HR)/AB },
wOBA = wOBA,
wRC = wRC)
})
rownames(stats) <- x$yearID
round(stats, 3)
}
当我打电话给removeSource()
时,我收到以下错误
> removeSource(.batStats)
# Error in recurse(part[[i]]) : argument "part" is missing, with no default
我不会在包中的任何其他函数中出现此错误,包括以.
开头的内部函数。此外,当我从recurse()
源代码中提取removeSource()
函数并执行
> recurse(.batStats)
没有错误。但是
出错了> recurse(body(.batStats))
# Error in attr(part, "srcref") <- NULL :
# argument "*tmp*" is missing, with no default
如何让removeSource()
使用此.batStats()
功能?
答案 0 :(得分:3)
错误似乎是由
引起的wData <- weightsData[rownames(weightsData) %in% x$yearID, ]
线。 removeSource()
正试图从每个元素中删除源,当它到达[,]
子集集中的空白索引时,它似乎触发错误,因为它无法从空索引中删除源
您可以将该行更改为
wData <- weightsData[rownames(weightsData) %in% x$yearID, seq_along(weightsData)]
避免错误。好像它可能是removeSource()
函数中的错误。最简单,可重复的例子是
test <- function(a) {
a[1,]
}
removeSource(test)