Open harakiricode opened 7 months ago
Thanks for the report! I cannot help much myself, unfortunately. I can only confirm the bug and add that this is an issue beyond gamlssCV()
or gamlssVGD()
. It occurs in general when you call gamlss()
with ri()
inside another function:
gamlss(y ~ ri(x.vars = c("x1", "x2")), data = usair) ## ok
fit_gamlss <- function(formula, data) gamlss(formula = formula, data = data) ## wrapper function
fit_gamlss(y ~ ri(x.vars = c("x1", "x2")), data = usair) ## fails
## Error in as.data.frame.default(x[[i]], optional = TRUE) :
## cannot coerce class '"function"' to a data.frame
And depending on what you use as the data name in the wrapper function you can also get other funny errors:
fit_gamlss <- function(formula, BOD) gamlss(formula = formula, data = BOD)
fit_gamlss(y ~ ri(x.vars = c("x1", "x2")), BOD = usair)
## Error in `[.data.frame`(Data, , x.vars) : undefined columns selected
In any case ri()
looks for an object with the name from inside the function (data
or BOD
above) in the environment outside the function. I've looked at the ri()
code and I'm not sure how easy it is to remedy this. Mikis @mstasinopoulos ?
When calling ri with gamlssCV,
get("gamlsscall", envir = gamlss.env)$data
returns the data function from the standard R utils package instead of the dataframe passed to the data argument of the gamlssCV call.Miminal reproducible example:
Full traceback: