


PUTRDATA Copies MATLAB data to an R variable.
PUTRDATA(VARNAME,DATA) puts MATLAB variable DATA into R variable
VARNAME. Not all R data types are supported by the (D)COM Server.
Version 1.2 supports scalars (booleans, integers, doubles and strings)
and arrays of these.
STATUS = PUTRDATA(VARNAME,DATA) returns true if the data was
successfully copied to R.
[STATUS, MSG] = PUTRDATA(VARNAME, DATA) 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');
getRdata('c')
% Close the connection.
closeR;
See also: CLOSER, GETRDATA, OPENR, PUTRDATA.

0001 function [status,msg] = putRdata(varname,data) 0002 % PUTRDATA Copies MATLAB data to an R variable. 0003 % 0004 % PUTRDATA(VARNAME,DATA) puts MATLAB variable DATA into R variable 0005 % VARNAME. Not all R data types are supported by the (D)COM Server. 0006 % Version 1.2 supports scalars (booleans, integers, doubles and strings) 0007 % and arrays of these. 0008 % 0009 % STATUS = PUTRDATA(VARNAME,DATA) returns true if the data was 0010 % successfully copied to R. 0011 % 0012 % [STATUS, MSG] = PUTRDATA(VARNAME, DATA) returns the text of any errors. 0013 % 0014 % Example: 0015 % 0016 % status = openR; 0017 % % Create a MATLAB variable and export it to R. 0018 % a = 1:10 0019 % putRdata('a',a) 0020 % 0021 % % Run a simple R command using the data 0022 % b = evalR('a^2') 0023 % 0024 % % Run a series of commands and import the result into MATLAB. 0025 % evalR('b <- a^2'); 0026 % evalR('c <- b + 1'); 0027 % getRdata('c') 0028 % % Close the connection. 0029 % closeR; 0030 % 0031 % See also: CLOSER, GETRDATA, OPENR, PUTRDATA. 0032 0033 % Robert Henson, May 2004 0034 % Copyright 2004 The MathWorks, Inc. 0035 0036 global R_lInK_hANdle 0037 0038 msg = ''; 0039 % Use the SetSymbol method to pass data. 0040 try 0041 R_lInK_hANdle.SetSymbol(varname,data); 0042 status = true; 0043 catch 0044 status = false; 0045 msg = lasterr; 0046 if nargout == 0 0047 error('Could not put data.\n%s',msg); 0048 end 0049 end 0050 if nargout ==0 0051 clear status 0052 end