[R] Optional arguments in stats::nls
rytis.bagdziunas at openanalytics.eu
Tue Feb 28 17:07:10 CET 2017
I've been struggling with the usage of ellipsis argument for stats::nls
and similar functions. In particular, nls manual indicates this:
...: Additional optional arguments. None are used at present.
However, "none are used" seems to be slightly misleading. Here's an
data <- data.frame("x" = rnorm(100),
"y" = rnorm(100))
fn <- function(y, a) a * y
## This works
nls(y ~ fn(x, a), data = data, start = list("a" = 1))
## This doesn't
nls(y ~ fn(x, a), data = data, start = list("a" = 1), myarg = FALSE)
## But this does
nls(y ~ fn(x, a), data = data, start = list("a" = 1), myarg = rnorm(100))
traceback() indicates that the additional argument is passed to
model.frame.default() but doesn't appear to do anything.
Is this expected behaviour?
More information about the R-help