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

Deepayan Sarkar deepayan at stat.wisc.edu
Sun Nov 28 18:25:02 CET 2004


On Sunday 28 November 2004 05:13, Peter Dalgaard wrote:
> rmh at 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 at 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



More information about the R-devel mailing list