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

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sun 28 Nov 2004 - 22:13:15 EST

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.

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). 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.

-- 
   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 Sun Nov 28 22:30:11 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:01:47 EST