From phgrosjean at sciviews.org  Sun Oct 29 17:16:57 2006
From: phgrosjean at sciviews.org (Philippe Grosjean)
Date: Sun, 29 Oct 2006 17:16:57 +0100
Subject: [Rd] how to determine if a function's result is invisible
In-Reply-To: <6phwt6jgog4.fsf@gopher4.fhcrc.org>
References: <971536df0610251714u451cf80fy80bf38cb2f130734@mail.gmail.com>	<454023EA.4020403@stats.uwo.ca>	<971536df0610252002s46ef72b2n32df3e180a49e990@mail.gmail.com>	<45403561.1000808@stats.uwo.ca>	<971536df0610260226o55726354j8cbdfa5af07ae508@mail.gmail.com>	<45438F9B.7000905@stats.uwo.ca>
	<4543D3A6.7010900@sciviews.org>	<4543FB75.7090405@stats.uwo.ca>
	<454478A8.9000903@sciviews.org>	<454485F3.1020206@stats.uwo.ca>
	<4544A5F3.70907@sciviews.org>	<4544B859.8010604@stats.uwo.ca>
	<6phwt6jgog4.fsf@gopher4.fhcrc.org>
Message-ID: <4544D3F9.4080500@sciviews.org>

Martin Morgan wrote:
>>> Yes, I know! That is why this code is NOT released to CRAN, and also why 
>>> I do NOT propose it as to John Fox or Jose-Claudio Faria as a patch for 
>>> R Commander or Tinn-R, respectively. We are precisely discussing the 
>>> problem to find better solutions (the R GUI API?). For instance, could 
>>> you suggest a better isLineComplete() function? I am pretty sure one 
>>> could get something better using C code, which is something I have not 
>>> attempted to do.
>> I don't know a better isLineComplete function currently, but if parse() 
>> returned more structured error information, it would be easy to write 
>> one.  (Of course, we might not need one in that case...)
>>
>> I think that's a better approach, and it's definitely something that I 
>> am interested in working on.  It seems to me to be a waste of my time to 
>> make internal changes that will not only allow, but *force* all GUI 
>> writers to replicate the R console.  It should be easy to do that (and 
>> it's not now), but it should also be easy to do something quite different.
> 
> Prof. Ripley improved the mechanism for handling this at the C level
> during the last release cycle. The basic strategy is
> 
> #include <R_ext/Parse.h>
> 
> SEXP parses(SEXP cmd, SEXP rho) {
>   ParseStatus status;
>   SEXP res = R_ParseVector(cmd, -1, &status);
>   switch(status) {
>   case PARSE_NULL:
>   case PARSE_OK:
>     break;
>   case PARSE_INCOMPLETE:
>     ...
>     break;
>   case PARSE_ERROR:
>     ...
>     break;
>   case PARSE_EOF:
>     ... /* not sure we ever reach here -- incomplete before eof */
>     break;
>   }
>   return res;
> }
> 
> my implementation of '...' is to signalCondition, so at the R level
> you can detect the outcome in a tryCatch, something like
> 
>         expr <- readLines(file, 1)
>         expr <- tryCatch(.Call("parses", expr, environment()),
>                          parse_incomplete = ...)
> 
> 
> Martin

Oh, very nice! I'll look at this. Many thanks.

Philippe




[Rd] how to determine if a function's result is invisible
Philippe Grosjean