Skip to content
Prev 6600 / 15075 Next

Interacting with R GUI app from another Cocoa app

On Nov 29, 2009, at 3:40 PM, Guillaume Chapron wrote:

            
Coding it should take at most, an hour, I would try it, you might be  
surprised.  Usually, I always code a working version then optimize  
it.  More than once, I have been surprised when the problem areas  
turned out to be completely different than I originally thought and I  
avoided a lot of additional complexity trying to solve a problem that  
did not exist.  If the simulation runs a few hours, spending a few  
more minutes reading and writing the results might be inconsequential.
You might follow this, http://developer.r-project.org/embedded.html to  
embed R into the Cocoa app.  I have no experience with this but it may  
lead you to something else.  You might also look at https://stat.ethz.ch/pipermail/r-sig-mac/2005-March/001706.html

Its possible to use interprocess communications to have R request the  
data from the Cocoa App.  However, there are a number of problems with  
this.  For example, the cocoa app has to be running.  When R is  
requesting the data it will be locked up waiting for the data.  You  
need to read state back and forth to know when to do what.  You will  
need to write an R extension in C, much the like the database  
extensions.  This seems like a lot of complexity to me.  In essence,  
your Cocoa GUI app would act like a database provider.

If R processing is segmenting the array at all, then you might be able  
to use a common database from both the Cocoa app and R.  A database  
just writes to a file with a lot more overhead, so if its not  
segmenting the array then you are probably better off reading a flat  
file as it all needs to be in memory at one time.
I would guess that writing to a file and importing into R would be  
much faster than using Applescript.
Then why not run R from the command line, you can have as many R  
instances running as you have machine (memory and CPUs), then use your  
original library version.