Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble reading/writing .mat files #171

Closed
lawsofthought opened this issue Jan 20, 2018 · 0 comments
Closed

Trouble reading/writing .mat files #171

lawsofthought opened this issue Jan 20, 2018 · 0 comments
Labels

Comments

@lawsofthought
Copy link

Trying to write a .mat file, I get an error.

library('rio')

Df <- data.frame(x = rnorm(10),
                 y = rnorm(10),
                 z = rnorm(10))


export(Df, "foo.mat")

Error in .export.default(file = file, x = x, ...) : Format not supported

So, I try

export(Df, "foo.mat", format='matlab')

and that works without complaint, and I can load foo.mat in octave and it looks good (but it is three 10 element vectors, x, y, and z).

Now, I try to read it in.

X <- import("foo.mat")

and trouble

Error in .import.default(file = file, ...) : Format not supported

So, I try,

X <- import("foo.mat", format='matlab')

but, although no errors, I get

> X
[1] x y z
<0 rows> (or 0-length row.names)

For comparison,

library(rmatio)
X <- read.mat('foo.mat')

and that works fine

> X
$x
 [1] -1.0852233  1.0429430  0.5547360  0.3567666  0.1246707  1.0751442  1.0522228 -0.8839636  0.5240233  0.7145037

$y
 [1]  1.2250672 -0.2555996  0.8573036 -2.6395863 -0.6556084  2.0775326  1.7713386 -1.3604206  0.5656115 -1.1923609

$z
 [1] -0.5950004  0.4543115 -0.9667500  2.5074521 -0.8083928 -0.1983492  0.4709925  0.1480296  0.6565982 -0.5104466

Am I missing a trick?

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS: /usr/lib/libblas.so.3.8.0
LAPACK: /usr/lib/liblapack.so.3.8.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] 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] rmatio_0.12.0 rio_0.5.5    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.11        lattice_0.20-35     grid_3.4.3          cellranger_1.1.0    magrittr_1.5        pillar_1.0.1       
 [7] rlang_0.1.6         readxl_1.0.0        curl_3.1            data.table_1.10.4-3 Matrix_1.2-12       openxlsx_4.0.17    
[13] forcats_0.2.0       tools_3.4.3         foreign_0.8-69      yaml_2.1.16         compiler_3.4.3      haven_1.1.0        
[19] tibble_1.4.1       

@leeper leeper added the bug label Jan 20, 2018
@leeper leeper closed this as completed in 1cc8854 May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant