[R] Detecting incomplete commands
phgrosjean at sciviews.org
Thu Dec 16 15:50:00 CET 2004
Thank you Thomas for your answer. This is of course what I intend to do
(indeed, to use a tryCatch(), instead of I try(). However, I would like to
have a different behaviour depending if the synthax is incorrect "ls())" for
instance, or incomplete "ls(" for instance. Indeed, exactly like the
distinction made at the command line:
> ls()) # This generates an error
Error: syntax error
> ls( # This is not an error, but a multiline command
If you use parse() within a try(), you got the same error message in both
cases: "Error in parse(file, n, text, prompt) : parse error". So, it is not
possible to discriminate between the two situation in this context. Is it a
way to cope with that?
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Thomas Petzoldt
> Sent: Thursday, December 16, 2004 3:18 PM
> To: phgrosjean at sciviews.org
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Detecting incomplete commands
> 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:
> > expression(ls())
> > This is fine!
> > 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  "Error
> in parse(file, n, text, prompt) : parse error\n"
>  "try-error"
> and then check if "ok" is an expression:
> > is.expression(ok)
> Thomas P.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide!
More information about the R-help