In brief, this package provides a one-directional interface from Rto MATLAB, with communication taking place via a TCP/IP connection and with data transferred either through another connection or via the file system. On the MATLAB side, the TCP/IP connection is handled by a small Java add-on.
The methods for reading and writing MAT files are stable. The Rto MATLAB interface, that is the Matlab class, is less prioritized and should be considered a beta version.
For package history, see showHistory(R.matlab)
.
To use the Matlab class or requesting verbose output messages, the R.utils package is loaded when needed (and therefore required in those cases).
The readMat()
and writeMat()
methods do $not$
require a MATLAB installation neither do they depend on the
Matlab
class.
To connect to MATLAB, MATLAB v6 or higher is required.
It does not work with MATLAB v5 or before (because those
versions do not support Java).
For confirmed MATLAB versions, see the Matlab
class.
install.packages("R.matlab")
readMat()
and writeMat()
see their help. For communication with a MATLAB server, use
matlab <- Matlab()
setVerbose(matlab, threshold=-2)
The lower the threshold is the more information you will see.
Cannot connect to MATLAB:
If R fails to connect to MATLAB, make sure to try the example in
help(Matlab) first. Make sure that the MATLAB server is running
before trying to connect to it from R first. If MATLAB is running
but open()
times out, make sure MATLAB is listening to the
same port that R is trying to connect to. If that does not help,
try to increase the time-out limit, see help(open.Matlab).
Expected an 'answer' from MATLAB, but kept receiving nothing.:
When launching a really long MATLAB process by evaluate()
, you
may get the above error message.
Reason: This happens because evaluate()
expect a reply
from MATLAB as soon as MATLAB is done. The waiting should be "blocked",
i.e. it should wait until it receives something. For unknown reasons,
this is not always happening. The workaround we have implemented is to
try readResult/maxTries
waiting readResult/interval
seconds
inbetween.
Solution:
Increase the total waiting time by setting the above options, e.g.
setOption(matlab, "readResult/interval", 10); # Default is 1 second
setOption(matlab, "readResult/maxTries", 30*(60/10)); # ~30 minutesMatlab$createShortcut()
which
creates a Windows shortcut to start the MATLAB server
by double clicking it. It should be possible to create
it in the current directory or to the Desktop.
Maybe it is possible to do this upon installation and
even to a Start -> All Programs -> R menu.who(matlab)
,clear(matlab)
etc.
Can this be done automatically using "reflection", so
that required arguments are automatically detected?"$"
and"$<-"
, e.g.matlab$A
andmatlab$A <- 1234
. Is this wanted?
Maybe the same for functions, e.g.matlab$dice(1000)
.
Is it possible to return multiple return values?If you consider implement some of the above, make sure it is not already implemented by downloading the latest "devel" version!
The development code of the packages is under a private licence (where applicable) and patches sent to the author fall under the latter license, but will be, if incorporated, released under the "release" license above.