"Philippe Grosjean" <[EMAIL PROTECTED]> writes:
> 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?
Here's one idea:
> grep("line 2",try(parse(textConnection("ls)")),silent=T))
numeric(0)
> grep("line 2",try(parse(textConnection("ls(")),silent=T))
[1] 1
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html