


GETRDATA Copies an R variable to MATLAB.
DATA = GETRDATA(VARNAME) gets the contents of R variable VARNAME.
[DATA, STATUS] = GETRDATA(VARNAME) returns true if the data was
successfully imported from R.
[DATA, STATUS, MSG] = GETRDATA(VARNAME) returns the text of any errors.
Example:
status = openR;
% Create a MATLAB variable and export it to R.
a = 1:10;
putRdata('a',a);
% Run a simple R command using the data
b = evalR('a^2')
% Run a series of commands and import the result into MATLAB.
evalR('b <- a^2');
evalR('c <- b + 1');
c = getRdata('c')
% Close the connection.
evalR('data(volcano)');
volcano = getRdata('volcano');
imagesc(volcano);
closeR;
See also: CLOSER, GETRDATA, OPENR, PUTRDATA.

0001 function [data,status,msg] = getRdata(varname) 0002 % GETRDATA Copies an R variable to MATLAB. 0003 % 0004 % DATA = GETRDATA(VARNAME) gets the contents of R variable VARNAME. 0005 % 0006 % [DATA, STATUS] = GETRDATA(VARNAME) returns true if the data was 0007 % successfully imported from R. 0008 % 0009 % [DATA, STATUS, MSG] = GETRDATA(VARNAME) returns the text of any errors. 0010 % 0011 % Example: 0012 % 0013 % status = openR; 0014 % % Create a MATLAB variable and export it to R. 0015 % a = 1:10; 0016 % putRdata('a',a); 0017 % % Run a simple R command using the data 0018 % b = evalR('a^2') 0019 % % Run a series of commands and import the result into MATLAB. 0020 % evalR('b <- a^2'); 0021 % evalR('c <- b + 1'); 0022 % c = getRdata('c') 0023 % % Close the connection. 0024 % evalR('data(volcano)'); 0025 % volcano = getRdata('volcano'); 0026 % imagesc(volcano); 0027 % closeR; 0028 % 0029 % See also: CLOSER, GETRDATA, OPENR, PUTRDATA. 0030 0031 % Robert Henson, May 2004 0032 % Copyright 2004 The MathWorks, Inc. 0033 0034 global R_lInK_hANdle 0035 0036 msg = ''; 0037 % get data using the handle.GetSymbol method. 0038 try 0039 data = R_lInK_hANdle.GetSymbol(varname); 0040 status = true; 0041 catch 0042 % errors from the server can be quite cryptic... 0043 data = []; 0044 status = false; 0045 msg = lasterr; 0046 if nargout == 0 0047 error('Could not get %s.\n%s',varname,msg); 0048 end 0049 end