


CLOSER Close connection to R server process
STATUS = CLOSER closes an R server process. STATUS is set to true if
the disconnection was successful, false otherwise.
[STATUS, MSG] = CLOSER returns any warning messages in the output MSG
and does not throw warnings.
CLOSER(HANDLE) closes the connection associated with handle HANDLE.
Example:
status = openR;
% Run one of the R demos to test the connection.
evalR('demo("persp")');
% Close the connection.
closeR;
See also: EVALR, GETRDATA, OPENR, PUTRDATA.

0001 function [status,msg] = closeR(handle) 0002 %CLOSER Close connection to R server process 0003 % 0004 % STATUS = CLOSER closes an R server process. STATUS is set to true if 0005 % the disconnection was successful, false otherwise. 0006 % 0007 % [STATUS, MSG] = CLOSER returns any warning messages in the output MSG 0008 % and does not throw warnings. 0009 % 0010 % CLOSER(HANDLE) closes the connection associated with handle HANDLE. 0011 % 0012 % Example: 0013 % 0014 % status = openR; 0015 % % Run one of the R demos to test the connection. 0016 % evalR('demo("persp")'); 0017 % % Close the connection. 0018 % closeR; 0019 % 0020 % See also: EVALR, GETRDATA, OPENR, PUTRDATA. 0021 0022 % Robert Henson, May 2004 0023 % Copyright 2004 The MathWorks, Inc. 0024 0025 global R_lInK_hANdle 0026 0027 msg = ''; 0028 status = false; 0029 % Check that we have a session to close. 0030 if nargin == 0 0031 if isempty(R_lInK_hANdle) 0032 0033 if nargout ==0 0034 error('No open R sessions to close.'); 0035 else 0036 msg = 'No open R sessions to close.'; 0037 end 0038 else 0039 handle = R_lInK_hANdle; 0040 end 0041 end 0042 % Close the connection and free the handle. 0043 try 0044 handle.Close; 0045 status = true; 0046 if isequal(handle,R_lInK_hANdle) 0047 R_lInK_hANdle = []; 0048 end 0049 catch 0050 if nargout ==0 0051 error('Cannot close R session.\n%s',lasterr); 0052 else 0053 msg = lasterr; 0054 end 0055 0056 end 0057 0058 if nargout ==0 0059 clear status; 0060 end 0061