Dear R-core team, We noticed a simple-to-fix bug in stats::polym() causing troubles in lm, lme4... Example: ``` mod <- lm(Petal.Length ~ poly(cbind(Petal.Width, Sepal.Length), 1), data = iris) predict(mod, newdata = data.frame(Petal.Width = 1, Sepal.Length = 1)) ``` crashes with the error ouput: "Error in `colnames<-`(`*tmp*`, value = apply(z, 1L, function(x) paste(x, : attempt to set 'colnames' on an object with less than two dimensions", but ``` mod <- lm(Petal.Length ~ poly(cbind(Petal.Width, Sepal.Length), 1), data = iris) predict(mod, newdata = data.frame(Petal.Width = 1, Sepal.Length = 1:2)) ``` works fine (notice the change from length of 1 to length 2 for Sepal.Length). For a RME directly involving the culprit, you may try: ``` test <- list(x = 1, z = 1) coefs <- list(list(alpha = 1, norm2 = c(1, 1, 1)), list(alpha = 1, norm2 = c(1, 1, 1))) polym(test, coefs = coefs) ``` The issue is that polym tries to define column names on a vector. Here is one possible fix for the definition of polym: ``` function (..., degree = 1, coefs = NULL, raw = FALSE) { [SNIP] if (is.null(coefs)) { [SNIP] } else { [SNIP] if (nd > 1) for (i in 2:nd) res <- res * cbind(1, poly(newdata[[i]], degree = degree, coefs = coefs[[i]], simple = TRUE))[, 1L + z[, i]] res <- matrix(res, nrow = 1L) ### FIX ### colnames(res) <- apply(z, 1L, function(x) paste(x, collapse = ".")) res } } ``` Best, Alexandre Courtiol and Colin Vullioud

Thank you Alexandre & Cortiol! Yes, this is indeed a bug... an infamously missing ', drop=FALSE' One remark: we consider "crash" to be a wrong use of word here: In our language, if R signals a regular error and continues to work fine afterwards, there's no crash. A typical crash is a segmentation fault (after which you must start R anew). I will commit the fix (and a regression test) to R-devel shortly, with the plan to port to "R 3.5.1 patched" within a day or two. Thank you in any case for your contribution to make R better! Martin