[R] R.matlab questions

Spencer Graves spencer.graves at pdf.com
Thu Jun 28 17:39:26 CEST 2007


Hello:

	  Two questions about R.matlab:

	  1.  How to break a hung R-Matlab connection?

	  2.  How to execute R.matlab commands from within a function?

	
BREAKING AN R-Matlab CONNECTION

	  Sometimes an attempted R.matlab command locks up my computer.  The 
standard R break process interrupts the R command.  However, when I do 
that, the command to Matlab is still pending, and I don't know an easy 
way to interrupt that.  A simple, self-contained example appears below.

	  The easiest way I've found so far to interrupt Matlab is to quit R. 
This will finally release Matlab.


CALLING R.matlab FUNCTIONS FROM WITHIN A FUNCTION

	  An R.matlab function call that works as a direct R command hangs for 
me when executed within an R function.  A simple, self-contained example 
appears below.

How can I work around this?


	  Thanks,
	  Spencer Graves
Using Matlab 7.3.0 (R2006b) under Windows XP Pro.
> sessionInfo()
R version 2.5.0 (2007-04-23)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] "splines"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "methods"   "base"

other attached packages:
R.matlab     R.oo      fda      zoo
  "1.1.3"  "1.2.7"  "1.2.1"  "1.3-1"

###################

#EXAMPLE:  CALLING R.matlab FROM WITHIN A FUCTION?

# 1.  library(R.matlab)
library(R.matlab)
# 2.  Create a Matlab client object to support communications
(matlab <- Matlab())
#     Optionally set setVerbose(..., -2) to get max info
setVerbose(matlab, -2)

# 3.  Start Matlab
# 4.  Ask Matlab to become a slave

#Matlab>> MatlabServer

# 5.  Open the connection from R to MatlabServer
(isOpenMatlab <- open(matlab))

# NOTE:  If Matlab is not frozen:
#R> close(matlab)
# returns local control to Matlab.
# Control of Matlab can be returned to R at any time
# by repeating steps 4 & 5.

# 6.  matlab.compute.a
compute <- evaluate(matlab, "a = 1+2")
(a0 <- getVariable(matlab, "a"))

# The above works fine for me.

# 7.  R.matlab.compute.a function
R.matlab.compute.a <- function(text="a=1+2", matlabClient=matlab){
# text = a Matlab expression that stores 'a'
   ev0 <- evaluate(matlabClient, text)
   getVariable(matlabClient, "a")
}

# The following locks up both R and Matlab for me:
R.matlab.compute.a()



More information about the R-help mailing list