From deepayan at stat.wisc.edu  Sun Nov 28 18:25:02 2004
From: deepayan at stat.wisc.edu (Deepayan Sarkar)
Date: Sun Nov 28 18:24:17 2004
Subject: [Rd] Is this a bug in the parser? (PR#7395)
In-Reply-To: <x2u0raw7jo.fsf@biostat.ku.dk>
References: <20041128043608.5CB7CEAC3@slim.kubism.ku.dk>
	<x2u0raw7jo.fsf@biostat.ku.dk>
Message-ID: <200411281125.02536.deepayan@stat.wisc.edu>

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


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