Skip to content

parse() does not complain for not finished strings?

2 messages · Philippe GROSJEAN, Peter Dalgaard

#
Hello,
parse() is supposed to detect incomplete instructions, isn't it?
For instance:
expression(log(10))
Error in parse(mc) : unexpected end of input at
2: log(
expression(text <- "some incomplete string\n")
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
#
Philippe Grosjean wrote:
A buglet at least. It is not parsing per se that does it:

 > parse(text=msg)
Error in parse(text = msg) :
  unexpected end of input in "text <- "some incomplete string"

but it happens whenever you parse from a file or connection e.g.

$ cat > xxx
"incom
$ R
[....]
 > source("xxx")
 > .Last.value
$value
[1] "incom\n"

$visible
[1] TRUE