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

stefano iacus jago at mclink.it
Tue Jun 28 22:11:38 CEST 2005


On 28/giu/05, at 20:14, Demitri Muna wrote:

> Hi Simon,
>
>
> On 28 Jun 2005, at 15:40, Simon Urbanek wrote:
>
>
>> you can do that fairly easily just using REngine. I have put
>> together a tiny sample project, you can download it from
>> http://research.att.com/~urbanek/REngineTest.dmg
>>
>
> That is absolutely brilliant - it's exactly what I was hoping to do.
> Thanks for the sample app; it worked perfectly and it's very
> illustrative. With that I can experiment with the rest of the API.
>
> Now, the final step for me is to display a plot.
>
>
>> All you need now is R installed as framework in /Library/
>> Frameworks. The demo app above includes REngine that is independent
>> of the R.app. Quartz won't work with that, though - you'd have to
>> get the Quartz classes from R.app (but it's possible).
>>
>
> I copied the following classes into the REngineTest you gave me:
> devQuartz.h/c, RQuartz.h/m, QuartzDevice.h/m, RDeviceView.h/m,
> RGUI.h, Preferences.h/m, PreferenceKeys.h, and RQuartz.nib. With a
> few minor changes (mainly commenting out "#import "../RController.h"
> lines), it compiled successfully.
>
> These seemed to be the minimum number of classes needed to include
> RQuartz, RDeviceView, and QuartzDevice. RQuartz.nib looks like the
> graphic window containing the custom NSView. I then tried to find
> where an RQuartz is instantiated (either directly or via
> loadNibNamed:@"RQuartz"), but I was not able to find it. I'm guessing
> that it's in QuartzDevice, innerQuartzDevice:, but I'm not sure where
> *that* is called from (or at least, how a plot command triggers it).

these are called by R when you try to open the quartz device. The  
code is inside src/library/grDevices/src/devQuartz.c  in the main R  
sources.
you just need to provide the callbacks and then ask R to open the  
quartz device as any other device, i.e. using R commands (i.e. quartz 
() instead of x11() that you tried)


> I copied newQuartzDevice: from RController, but there was no result.
> What am I missing to be able to connect the R engine in my app to the
> Quartz view?
>
> It then struck me that I could just as easily use X11 displays, and
> that worked the first time I tried it. the only problem - the display
> does not refresh on a resize. I noted that X11 displays do refresh
> when called from R.app - what is the callback that will let me know
> when to redraw the window?


if you look at Rcontroller.m (in R.app sources)

you need to fire a timer to check for X11 activity. The relevant code is

timer = [NSTimer scheduledTimerWithTimeInterval:0.05
                                              target:self
                                            selector:@selector 
(otherEventLoops:)
                                            userInfo:0
                                             repeats:YES];


- (IBAction)otherEventLoops:(id)sender {
     R_runHandlers(R_InputHandlers, R_checkActivity(0, 1));
}




> Do you buffer it or actually resubmit the
> plot command(s)?
no, R (interactive) devices now how to re-plot their content upon  
resize etc,

btw, don't rely too much on the current structure of the quartz  
device or at least check from time to time R.app sources. We have  
planned to do major changes to the quartz device to allow for more  
interactivity


stefano

>
> Thank you very much for all your help. I'm really pleased with the
> results!
>
> Cheers,
>
> Demitri
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>
>



More information about the R-SIG-Mac mailing list