From p.dalgaard at biostat.ku.dk  Sat Dec 29 00:42:14 2007
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sat, 29 Dec 2007 00:42:14 +0100
Subject: [Rd] parse() does not complain for not finished strings?
In-Reply-To: <47757290.5000301@sciviews.org>
References: <47757290.5000301@sciviews.org>
Message-ID: <477589D6.7000807@biostat.ku.dk>

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



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