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

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Wed 01 Sep 2004 - 00:40:57 EST

"Gabor Grothendieck" <ggrothendieck@myway.com> writes:

> Peter Dalgaard <p.dalgaard@biostat.ku.dk> writes:
> >
> > "Gabor Grothendieck" <ggrothendieck@myway.com> writes:
> >
> > > > > as.character(attr(terms(`a(b)`~`c(d)`),"variables"))
> > > > [1] "list" "`a(b)`" "`c(d)`"
> > > >
> > > > whereas for instance
> > > >
> > > > > sapply(attr(terms(`a(b)`~`c(d)`),"variables")[-1],as.character)
> > > > [1] "a(b)" "c(d)"
> > >
> > > 1. That is quite subtle but a fix based on that would appear to
> > > solve it.
> >
> > Hmm, not quite. I tried, and terms like offset(foo) gets me in
> > trouble. Probably, I was fixing the wrong end of the original problem:
> > In the comparisons, we can't have one side with backquotes and the
> > other without them. That doesn't have to mean that they should be
> > removed from both sides, and indeed it would get us in trouble if
> > someone was perverse enough to do things like
> >
> > y ~ `offset(foo)` + offset(foo)
> >
> > I.e. perhaps the real issue is that names(data) gets generated without
> > backquotes.
> >
> > Anyways, this is a real can of worms and I'm not sure we're not too
> > close to 2.0.0 to start tampering with it...
>
> How about a partial fix that does not address pathological
> cases where the variable names themselves have embedded
> backquotes but does address the common cases such as:
>
> y <- ts(1:10); x1 <- y^2; x2 <- y^4
> lm(`lag(y)` ~ ., cbind(lag(y), x1, diff(x2)) )
>
> without having to resort to:
>
> lm(lag.y ~ ., cbind(lag.y = lag(y), x1, diff(x2)) )
>

Hmm, I can get that example to run by using sapply(...,deparse)[-1] in about three places, without breaking make check except that it choked on one example in survival which needs width=500 added.

Still doesn't solve the ~ `offset(foo)` + offset(foo) issue though, and I'm beginning to suspect that that would require a complete redesign. Thing is that `offset(foo)` only makes sense if the column is named "offset(foo)" with no ``, but model.frame and friends will turn an offset(foo) term into a column with exactly the same name.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed Sep 01 00:51:55 2004

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