Re: [Rd] parse():ing a unclosed string

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 14 Aug 2005 - 21:24:28 GMT

On Sun, 14 Aug 2005, Henrik Bengtsson wrote:

> When parse():ing R code from *file* with a unclosed string, that is, a
> string that has an open quoation mark, but not a ending one, the string
> seems to be closed automagically. Is this a "bug"?

It's clearly intentional from the comments in the sources: EOF during parsing is treated specially.

Generally the parser has not been written to find all syntactic errors: in any case one would need a formal language definition to do that. Prior to R-devel quite a few mal-formed constants were accepted, for example.

> Example:
>
> > code <- "x <- '123";
> > parse(text=code) # Gives an error as expected
> Error in parse(file, n, text, prompt) : parse error
>
> > cat(file="foo.R", code)

What exactly is in this file?

> > expr <- parse("foo.R") # Closes the open string
> > print(expr)
> expression(x <- "123\n")
>
> Parsing from stdin(), that is parse(), gives an error too.

Those are _not_ the same thing. I am not clear what you actually tried, as you cannot generate an EOF this way.

> Platform: Windows XP Pro SP2, R Version 2.1.1 Patched (2005-07-20) as
> well as R Version 2.2.0 Under development (unstable) (2005-07-19 r34991).

These are rather old for non-released versions: there have been many changes since then (especially in R-devel).

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon Aug 15 07:33:32 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:16 GMT