Re: [Rd] Is this a bug in the parser? (PR#7395)

From: Deepayan Sarkar <deepayan_at_stat.wisc.edu>
Date: Mon 29 Nov 2004 - 04:25:02 EST

On Sunday 28 November 2004 05:13, Peter Dalgaard wrote:
> rmh@temple.edu writes:
> > # Your mailer is set to "none" (default on Windows),
> > # hence we cannot send the bug report directly from R.
> > # Please copy the bug report (after finishing it) to
> > # your favorite email program and send it to
> > #
> > # r-bugs@r-project.org
> > #
> > ######################################################
> >
> >
> >
> > <<insert bug report here>>
> > Is this a bug in the parser?

>

> No (how could it be? If anything, this has to do with _de_parsing).
> It's a bug (two, actually) in lattice, which has a maintainer....
>

> Inside latticeParseFormula
>

> parseCond <- function(model) {
> model <- eval(parse(text = paste("~", deparse(model))))[[2]]
> model.vars <- list()
> ....
>

> and later on in the same function
>

> names(ans$condition) <- sapply(modelRHS.vars, deparse)
>

> both of which whill get you in trouble if deparse needs multiple
> lines. Notice that paste("~", deparse(model)) will prepend a "~" to
> _every_ line, where only the first was intended, so you could have
> gotten a parse error there and then.

Thanks for figuring that out so quickly. Would have taken me much longer.

> The first bug is the sort of construct that I have been warning
> people about repeatedly; computing on the language by going through
> the textual representation as in parse(...deparse(...)) is almost
> always wrong. In this particular case, I think the code is equivalent
> to

>

> model <- substitute(~ m, list(m = model))
>
> (minus the bug, of course).

Right.

> Bug #2 is probably just that you need to take only the first line of
> deparse(), since you wouldn't want or need the fully deparsed object
> for a name.

Deepayan



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Nov 29 04:33:22 2004

This archive was generated by hypermail 2.1.8 : Mon 29 Nov 2004 - 05:12:47 EST