[R-SIG-Mac] Interacting with R GUI app from another Cocoa app

Neil Tiffin neilt at neiltiffin.com
Sun Nov 29 21:16:25 CET 2009


On Nov 29, 2009, at 9:29 AM, Guillaume Chapron wrote:

> Hello,
>
> I have a standalone simulation model written in Objective C/Cocoa.  
> Once the simulations are done, I would like to send the output (a  
> large C array) to R.app for further analysis and plotting. I'm able  
> to launch R.app from a Cocoa app by this:
>
> 	[[NSWorkspace sharedWorkspace] launchApplication:@"R.app"];
>
> But I'm not able to send the C array or in fact any kind of  
> instructions. I have tried a modified code:
>
> 	NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/R.app"];
> 	NSString *path = [bundle executablePath];
> 	NSTask *task = [[NSTask alloc] init];
> 	
> 	[task setLaunchPath:path];
> 	[task setArguments:[NSArray arrayWithObject:@"2+3"]];
> 	[task launch];
>

You might try to write the results into a file and read it back in R.   
This is probably safer anyway.

> But it seems that R.app does not understand the arguments of the  
> NSTask. How from my Cocoa app, can I tell R.app to read a pointer to  
> a C array and convert it to a R object, and how can I send R  
> instructions?
>
> Before I wrote the Objective C model as a dyn library and I could  
> call it from R and run the simulations, but because simulations last  
> hours, I cannot use R.app during that time, so I'm trying to do the  
> reverse, interact with R from a Cocoa app once the simulations are  
> done. Has anyone done something like that?
>

Why not run the original dyn library simulation as another user, then  
the current user can do whatever they want with R?  To do this enable  
"fast user switching" in the "Accounts" preference.  Now you can leave  
a program running as one user and log in as another user to do  
something else.  Of course, you will need to create a 2nd user account.



More information about the R-SIG-Mac mailing list