Skip to content
Prev 27 / 1236 Next

[R-gui] Re: R-SIG-GUI digest, Vol 1 #3 - 9 msgs

Duncan Murdoch wrote:
Thanks for the feedback.
That is quite easy to do.  That's how we write most of the
inter-system interfaces that embed R, e.g. Gnumeric, Netscape, Python,
Perl, Java, and so on.  I have heard some people mention this problem
before, and when I discussed it with them we determined that they were
running the R_mainloop() routine (or its equivalent). That's why R
thought it was in charge.  The proper thing to do is just call R's
initialization routine which sets up the engine for computation, but
stop there and your application assumes control.  Then in any callback
(or whatever is approriate for your application), you can use
R_tryEval() to evaluate any S expression.  When you initialize the R
engine, you can tell it that it is not interactive (although it knows
that itself) and can give it command line arguments.  (This does work
best on Unix as the Windows initialization is not similar and done in
a separate piece of code. But it does work.)
No problem. Just arrange for that object to either call the relevant
internal C routine in the R C code, or have it create an expression
(in C) and evaluate that using R_tryEval(). Then extract the information
as appropriate from the resulting SEXP. If the expression becomes
anything more complex than  calling a function with a few arguments,
write a function in S that takes care of doing the computations and call it.
Good luck. That's a tricky thing to do, in general, without threads.
So on Windows, you can do it using threads.  But you can send an
signal to the process on Unix. But of course you'll have to do it from
another process or thread since there is no way to get access to the
prompt. We may be able to do things in the near future using readers
and idle tasks.
If you really want to do that (I don't think it works in general
except when relaying the output, e.g., directly to another display),
just call a myEval() function which sinks the output to a
textConnection() and return the result.  One can also use the
taskCallback mechanism to have the result handled in a particular
way. I am a big fan of event-driven programming and using callbacks
to modularize behaviour that can be dynamically specified.
I would think it is best to write a graphics device and when you start
R load the code that implements that into R. I don't think there is a
need for the application to be told by R that it wants to draw
graphics.  An event driven model handles this better.
Exceptions will do this. We have discussed putting them in for I
believe 3 1/2 years now and I brought it up again recently.  Hopefully
those that have designed the mechanism will get a chance to put them
in. 


So all these are great to know about. More documentation is needed for
how to run R as an embedded engine. I'll do this as time permits.
Exceptions will be a very useful addition.

Thanks.

 (a different) Duncan
Message-ID: <20021017232216.A2786@jessie.research.bell-labs.com>
In-Reply-To: <nspuqu043faimlaductvvt20ds6psep7s0@4ax.com>; from dmurdoch@pair.com on Thu, Oct 17, 2002 at 10:10:00PM -0400