Calling R from Matlab
This uses the COM interface,
so only works on Windows.
Trouble shooting
- If it's not working
make sure the Dcom service is running under Control Panel --> Administrative Tools --> Services --> DCOM Server Process Launcher.
You can start the service by right clicking and selecting 'start',
(unless of course its already running) and have it always start on
reboot by double clicking and changing the startup type to automatic.
-
The Rsvr install creates a bunch of shortcuts under the R program folder on the start bar. One of these, "server 01 Basic Test" will test the
connection to R - if that works we know the problem is between Matlab
and Dcom and also unlikely to be a firewall problem.
Example
A matlab wrapper to the
glasso
function.
function precMat = glassoR(C, rho, useMBapprox)
% Use L1-linear regression to find markov blankets and then Lambda.
% Uses R code from http://www-stat.stanford.edu/~tibs/glasso/
openR;
evalR('C<-1') % must pre-declare variable before writing a matrix
evalR('L<-1')
putRdata('C',C);
putRdata('rho',rho);
putRdata('useMBapprox', useMBapprox)
evalR('stuff <- glasso(C,rho=rho,approx=useMBapprox)');
evalR('L <- stuff$wi') % inverse covariance matrix
precMat = getRdata('L');
closeR;