我继承了一些使用我认为是库的常见 R 习惯用法的代码,但我不确定以这种冗长的方式编写会实现什么。最终我打算重写,但在我做一些愚蠢的事情之前,我首先想知道为什么。
ecd <-
function(formula, data, subset, weights, offset, ...) {
cl = match.call()
mf = match.call(expand.dots = FALSE)
m =
match(c("formula", "data", "subset", "weights", "offset"),
names(mf),
0L)
mf = mf[c(1L, m)]
mf$drop.unused.levels = TRUE
mf[[1L]] = quote(stats::model.frame)
mf = eval(mf, parent.frame())
mt = attr(mf, "terms")
y = stats::model.response(mf, "numeric")
w = as.vector(stats::model.weights(mf))
offset = as.vector(stats::model.offset(mf))
x = stats::model.matrix(mt, mf, contrasts)
z = ecd.fit(x, y, w, offset, ...)
我目前的理解是它从函数的原始参数构造一个函数调用对象(类型?)然后手动调用它,而不是直接调用stats::model.frame。任何见解将不胜感激。