I am trying to use anova.ccabyterm (but this also concerns *byaxis and *bymargin) within a function.
Example
For example using the pyrifos data and to run a RDA for every week, I could do something along these lines:
data(pyrifos)
week <- gl(11, 12, labels=c(-4, -1, 0.1, 1, 2, 4, 8, 12, 15, 19, 24))
dose <- factor(rep(c(0.1, 0, 0, 0.9, 0, 44, 6, 0.1, 44, 0.9, 0, 6), 11))
# RDA per week
out <- NULL
for (i in levels(week)) {
out[[i]] <- anova(rda(pyrifos[week == i, ] ~ dose[week==i]), by = "terms")
}
# works!
However wrapping into a function breaks:
foo2 <- function(response, treatment, time){
out <- NULL
for (i in levels(time)) {
out[[i]] <- anova(rda(response[time == i, ] ~ treatment[time==i]), by = 'terms')
}
return(out)
}
foo2(response = pyrifos, treatment = dose, time = week)
# Error in eval(expr, envir, enclos) : object 'response' not found
The error throws along the lines of model.frame.cca. Any Ideas?
I am trying to use anova.ccabyterm (but this also concerns *byaxis and *bymargin) within a function.
Example
For example using the pyrifos data and to run a RDA for every week, I could do something along these lines:
However wrapping into a function breaks:
The error throws along the lines of
model.frame.cca. Any Ideas?