I would like to execute the following function:
library(glmulti)
jmra <- function(fname){
mydata <- read.csv(fname)
myvars <- c('X1', 'X2', 'X3', 'X4', 'X5', 'X6')
formula <- paste('Y ~', paste(myvars, collapse='+'))
glmulti.lm.out <- glmulti(formula, data=mydata, level=1, method="h", crit="aicc", confsetsize=50, plotty=F, report=F, fitfunction='lm')
return(glmulti.lm.out)
}
test <- jmra('test.csv')
However, what I get is this error message:
Error in glmulti(y = Y ~ X1 + X2 + X3 + X4 + X5 + X6 : object 'mydata' not found
Interestingly, everything works fine if the same code is outside of this function. So what is happening here?