[Rd] parse():ing a unclosed string
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sun Aug 14 23:24:28 CEST 2005
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 at 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
More information about the R-devel
mailing list