[Rd] parse() does not complain for not finished strings?
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Sat Dec 29 00:42:14 CET 2007
Philippe Grosjean wrote:
> Hello,
> parse() is supposed to detect incomplete instructions, isn't it?
> For instance:
>
>
>> # Correct code
>> msg <- 'log(10)'
>> mc <- textConnection(msg)
>> parse(mc)
>>
> expression(log(10))
>
>> 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
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
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel
mailing list