Rank: 100389 based on 0 downloads (last 30 days) and 0 file submitted
photo

Max

E-mail

Personal Profile:
Professional Interests:

 

Watch this Author's files

 

Comments and Ratings by Max
Updated File Comments Rating
11 Feb 2011 MATLAB R-link Functions for calling the statistical package R from within MATLAB. Author: Robert Henson

As now R version is 2.12.1, here is my solution.
for a clean install R, install package rscproxy (ver 1.3-1), and http://rcom.univie.ac.at/download/current/statconnDCOM.latest.exe (ver 3.1-2B7)
then Start->All Programs->statconn->DCOM->Server01 – Basic Test, to verify that everything is working.

now back to matlab (R2010b), run the following code

hr = actxserver('StatConnectorSrv.StatConnector');
hi = hr.invoke;
%fire up R
hr.Init('R');
% Push data into R
a = 1:10;
hr.SetSymbol('a',a);
% Run a simple R command
b = hr.Evaluate('a^2')
% Run a series of commands and grab the result
hr.EvaluateNoReturn('b <- a^2');
hr.EvaluateNoReturn('c <- b + 1');
c = hr.GetSymbol('c')
% Close the connection
hr.Close

which will produce
b =

1 4 9 16 25 36 49 64 81 100

c =
2 5 10 17 26 37 50 65 82 101

note that
hi = hr.invoke

hi =

Init: 'void Init(handle, string)'
Close: 'void Close(handle)'
GetSupportedTypes: 'int32 GetSupportedTypes(handle)'
GetSymbol: 'Variant GetSymbol(handle, string)'
SetSymbol: 'void SetSymbol(handle, string, Variant)'
Evaluate: 'Variant Evaluate(handle, string)'
EvaluateNoReturn: 'void EvaluateNoReturn(handle, string)'
GetErrorId: 'int32 GetErrorId(handle)'
GetErrorText: 'string GetErrorText(handle)'
AddGraphicsDevice: 'void AddGraphicsDevice(handle, string, handle)'
RemoveGraphicsDevice: 'void RemoveGraphicsDevice(handle, string)'
SetUserInterfaceAgent: 'void SetUserInterfaceAgent(handle, handle)'
SetCharacterOutputDevice: 'void SetCharacterOutputDevice(handle, handle)'
SetErrorDevice: 'void SetErrorDevice(handle, handle)'
SetTracingDevice: 'void SetTracingDevice(handle, handle)'
GetServerInformation: 'string GetServerInformation(handle, InformationType)'
GetConnectorInformation: 'string GetConnectorInformation(handle, InformationType)'
GetInterpreterInformation: 'string GetInterpreterInformation(handle, InformationType)'

Remarks
1 the rcom package for R is not necessary
2 we dont need the "MATLAB R-link" to wrap the com automation.

Contact us