[R] Detecting incomplete commands

Thomas Petzoldt thpe at hhbio.wasser.tu-dresden.de
Thu Dec 16 15:17:55 CET 2004


Philippe Grosjean wrote:
> Hello,
> 
> I need a similar behaviour as with the prompt: asking to complete incomplete
> R command with eval(parse(text = ....))
> Is it a way to make the difference between an illegal and an incomplete R
> command in a string?
> For instance:
> 
> 
>>parse(text="ls()")
> 
> expression(ls())
> 
> This is fine!
> 
> 
>>parse(text="ls(")
> 
> Error in parse(file, n, text, prompt) : parse error
> 
> This is an incomplete command, and I want to ask to the user for further
> input (multiline command)

Hello Phillipe,

why not using something like this:

 > ok<-try(parse(text="ls("), silent=TRUE)
 > ok
[1] "Error in parse(file, n, text, prompt) : parse error\n"
attr(,"class")
[1] "try-error"

and then check if "ok" is an expression:

 > is.expression(ok)
FALSE


Thomas P.




More information about the R-help mailing list