[R-SIG-Mac] Call R framework from my own Cocoa app?

Demitri Muna thatsanicehatyouhave at mac.com
Tue Jun 28 15:29:58 CEST 2005


Thanks to both Stefano and Simon for your quick replies! I've been  
poring through the code, and have found it very interesting.

On 27 Jun 2005, at 18:12, Simon Urbanek wrote:

> Yes=write Cocoa application for R, no=write Cocoa application for  
> GUI (although it's not quite clear what you mean by that).

Basically, I was optimistically hoping to be able to write a Cocoa  
app that would construct small R scripts, pass them to a black box,  
and get the image back. I'm not trying to reinvent (your) wheel, just  
hide all the details from the user.

I was not really expecting to interact with the existing gui,  
although the AppleScript suggestion is very interesting. With a Cocoa  
app generating the scripts based on user input, this may pretty much  
solve what I'd like to do. Not as self-contained as initially  
envisioned, but probably easier. :)

I've already had a stab at it, and have a bare bones Cocoa app  
sending scripts to R via AppleScript and generating plots. It's  
working quite well (although debugging the AppleScripts is not as  
clean as I'd like!). The biggest problem I've come across is speed. I  
have 10,000 data points I'd like to plot, so in the AppleScript I do  
something like this:

y = c(0, 1, 2, ...., 9999) # not a sequence, but real data

I can't read the data from a file since I'm getting it live from a  
remote web site. It takes about 0.5-0.9s to read the data from the  
server, and 2-5 seconds to execute the AppleScript (on a 450MHz G4 -  
hey, I love my Cube!). It's taking a fair bit longer (up to 10-12  
seconds) beyond this to see the plot. My guess is that it is taking a  
while to print all 10,000 values in the R document window, which it  
does before plotting. Can anyone suggest a improvement here? While  
this is bad, I actually need to plot 18,000 points (18 of these arrays).

> We can always use experienced Cocoa programmers - they are rather  
> rare so far ;).

Ah.. but the opportunities. :) Unfortunately, I don't have a lot of  
time to spend on another project (so many unfinished ones...plus grad  
school...). However, I would be curious to see how difficult it would  
be to make the R framework standalone. An app could link against it,  
talk to R directly, and maybe even use something like Aquaterm (or  
your custom view) to produce the plots. I think R.app is great as it  
is for interactive use, but it would be interesting to see the input  
completely wrapped by Cocoa for custom uses.

I spent a few minutes trying to add REngine to my app, but the  
dependencies grew pretty quickly. :)

Thanks again for your help!

Cheers,

Demitri



More information about the R-SIG-Mac mailing list