[R] model.tables call fails with "Error in inherits(object, "formula")"

Hannes ghan at gmx.at
Fri Jul 23 13:53:49 CEST 2010


Hello,

I noticed that model.tables fails when applied to an aov() fit if called 
inside a function. The problem seems to occur when as.formula is used 
inside a function on a string containing
"<formula> + Error( x / y )"

The reason I tried to use as.formula is to generate dynamic calls to aov().
Here is a minimal example illustrating the problem:

## Example

test <- function(dat) {
     frmlb <- "yield ~ block";                    # WORKS
     aovfit <- aov(as.formula(frmlb), dat);
     print(model.tables(aovfit, "means"));

     frmlc <- "yield ~ block + Error(N/block)";   # DOES NOT WORK
     aovfit <- aov(as.formula(frmlc), dat);
     print(model.tables(aovfit, "means"));
}

utils::data(npk, package="MASS");
frmla <- "yield ~ block + Error(N/block)";       # WORKS
aovfit <- aov(as.formula(frmla), npk);
print(model.tables(aovfit, "means"));
test(npk);

## End of example


Output of sessionInfo():
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[1] LC_COLLATE=Finnish_Finland.1252  LC_CTYPE=Finnish_Finland.1252
[3] LC_MONETARY=Finnish_Finland.1252 LC_NUMERIC=C
[5] LC_TIME=Finnish_Finland.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_2.11.1

br Hannes G.



More information about the R-help mailing list