Skip to content
Prev 6602 / 15075 Next

Interacting with R GUI app from another Cocoa app

Guillaume,
On Nov 29, 2009, at 10:29 , Guillaume Chapron wrote:

            
R.app is a a LS app so it doesn't process command line arguments. You  
can talk to R.app using AppleScript (see the FAQ).
I think you're approaching this form the wrong end. You can load  
arbitrary C/Obj-C code into R (see R-ext) and that is how you can  
create R objects from C arrays (or rather you allocate the R object  
instead of using malloc). You can use the RController object to talk  
to the R.app GUI if you wish - e.g. you may be able to use the Cocoa  
package
http://rforge.net/Cocoa
to call Obj-C code such as issuing Obj-C messages from R.
There are two issues depending how you define "cannot use R.app".  
First, you should be calling R_CheckUserInterrupt() periodically to  
make sure your simulation doesn't block R and the GUI.

Second, if you really want to simulation to run entirely in parallel,  
you can simply create a separate thread in your simulation code such  
that your initialization function returns back to R as soon as all  
objects are preserved or copied so R can continue to work while your  
simulation is running on a separate thread. Then you can always check  
the objects from the R code to see if it has finished and yet you can  
safely work in parallel. The only restriction is that your threaded  
code may not call any R API functions as soon as it dispatches the new  
thread, but that's usually ok if you allocate the R objects before that.

Cheers,
Simon