RE: [Rd] model.matrix.default chokes on backquote (PR#7202)

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Sat 28 Aug 2004 - 14:26:52 EST

Sorry, but my solution itself had a shortcoming. The $ at the end of the regular expression is missing and gsub can simply be sub. Here it is again:

     strip.backquote <- function(x) sub("^`(.*)`$", "\\1", x)
     reorder <- match(strip.backquote(attr(t, "variables"))[-1],
               strip.backquote(names(data)))



Full_Name: Gabor Grothendieck
Version: R version 1.9.1, 2004-08-03
OS: Windows XP
Submission from: (NULL) (207.35.143.52)

The following gives an error:

> `a(b)` <- 1:4
> `c(d)` <- (1:4)^2
> lm(`a(b)` ~ `c(d)`)

     Error in model.matrix.default(mt, mf, contrasts) :
     model frame and formula mismatch in model.matrix()

To fix it replace this line in model.matrix.default:

     reorder <- match(attr(t, "variables")[-1], names(data))

with these two lines:

     strip.backquote <- function(x) gsub("^`(.*)`", "\\1", x)
     reorder <- match(strip.backquote(attr(t, "variables"))[-1],
               strip.backquote(names(data)))

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Aug 28 14:30:51 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:45:10 EST