[Rd] parse() does not complain for not finished strings?

Philippe Grosjean phgrosjean at sciviews.org
Fri Dec 28 23:02:56 CET 2007

parse() is supposed to detect incomplete instructions, isn't it?
For instance:

> # Correct code
> msg <- 'log(10)'
> mc <- textConnection(msg)
> parse(mc)
> close(mc)

> # Now, an incomplete code
> msg <- 'log('
> mc <- textConnection(msg)
> parse(mc)
Error in parse(mc) : unexpected end of input at
2: log(
> close(mc)

> # Now, another incomplete code (character string not finished)
> msg <- 'text <- "some incomplete string'
> mc <- textConnection(msg)
> parse(mc)
expression(text <- "some incomplete string\n")
> close(mc)

I don't understand why parse() does not complain in this third case, and
why it "finishes" my string and adds a '\n' at its end. Does anybody
could explain me,... or is this a bug?
Many thanks.

Philippe Grosjean

More information about the R-devel mailing list