[R] writeMat error

Steele, Dr Douglas d.steele at abdn.ac.uk
Sat Sep 27 14:17:38 CEST 2008


Hi

I am using Ubuntu 8.04 64 bit, R as below, Matlab 7.6.0.  I would like to transfer mat files back and forward between R and Matlab.  Whilst I have used Matlab for years its been a long time since I have used R (hence question may be a bit simple)

Running code

A  <-  c(1:10)
dim(A) <- c(2,5)
library(R.matlab)
writeMat('A.mat', A=A)

Does not appear to generate any mat file either in local directory or in /tmp/R*

I tried both current version of R.matlab and older version because of bug
https://stat.ethz.ch/pipermail/r-help/2008-September/173432.html

A <- matrix(1:27, ncol=3)
B <- as.matrix(1:10)
fn <- paste(tempfile(), ".mat", sep="")
writeMat(fn, A=A, B=B)
data <- readMat(fn)
print(data)
unlink(fn)
onWrite <- function(x)
writeBin(x$length, con=x$con, size=4, endian="big");
writeMat(fn, A=A, B=B, onWrite=onWrite)

Does generate a file in /tmp/Rtmpjhfjxw
-rw-r--r--  1 dst dst  396 2008-09-27 12:46 file643c9869.mat

When I try to read it into Matlab I get

??? Error using ==> load
Unable to read MAT-file /tmp/Rtmpjhfjxw/file643c9869.mat

File may be corrupt.

(This is same error message as above link and occurs with old and current version of R.matlab)

Any advice would be very helpful

Regards

Douglas



> sessionInfo()
R version 2.6.2 (2008-02-08)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C

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

other attached packages:
[1] R.matlab_1.2.1    R.oo_1.4.6        R.methodsS3_1.0.3

loaded via a namespace (and not attached):
[1] rcompgen_0.1-17
>


The University of Aberdeen is a charity registered in Scotland, No SC013683.



More information about the R-help mailing list