Skip to content

model.matrix.default chokes on backquote (PR#7202)

3 messages · Gabor Grothendieck, Peter Dalgaard

#
Peter Dalgaard <p.dalgaard@biostat.ku.dk> writes:
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)) )
#
"Gabor Grothendieck" <ggrothendieck@myway.com> writes:
Hmmm... Point taken, but I'm not happy about the fact that the
internals seem unable to  discern `lag(y)` (the name) and lag(y) (the
call). One might consider "backtickifying" the names of the data
matrix instead:
function(nm)deparse(as.name(nm),backtick=TRUE))
a     a(b)
     "a" "`a(b)`"
1 day later
#
"Gabor Grothendieck" <ggrothendieck@myway.com> writes:
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.