R Under development (unstable) (2023-12-12 r85669 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## rmatio, a R interface to the C library matio, MAT File I/O Library. > ## Copyright (C) 2013-2023 Stefan Widgren > ## > ## This program is free software: you can redistribute it and/or modify > ## it under the terms of the GNU General Public License as published by > ## the Free Software Foundation, either version 3 of the License, or > ## (at your option) any later version. > ## > ## rmatio is distributed in the hope that it will be useful, > ## but WITHOUT ANY WARRANTY; without even the implied warranty of > ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ## GNU General Public License for more details. > ## > ## You should have received a copy of the GNU General Public License > ## along with this program. If not, see . > > library(rmatio) > > ## For debugging > sessionInfo() R Under development (unstable) (2023-12-12 r85669 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: [1] LC_COLLATE=C LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=C LC_NUMERIC=C [5] LC_TIME=C time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rmatio_0.19.0 loaded via a namespace (and not attached): [1] compiler_4.4.0 Matrix_1.6-4 grid_4.4.0 lattice_0.22-5 > > ## > ## Check write and read of array in MAT5 format: > ## 1) without compression > ## 2) with compression > ## > > ## > ## array: case-1 > ## > a1_exp <- array(seq_len(32^3), c(32, 32, 32)) > storage.mode(a1_exp) <- "integer" > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a1_exp), filename = filename, compression = FALSE, + version = "MAT5") > a1_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a1_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a1_obs, a1_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a1_exp), filename = filename, compression = TRUE, + version = "MAT5") > a1_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a1_zlib_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a1_zlib_obs, a1_exp)) > > ## > ## array: case-2 > ## > a2_exp <- array(seq_len(32^3), c(32, 32, 32)) > storage.mode(a2_exp) <- "double" > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a2_exp), filename = filename, compression = FALSE, + version = "MAT5") > a2_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a2_obs) num [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a2_obs, a2_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a2_exp), filename = filename, compression = TRUE, + version = "MAT5") > a2_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a2_zlib_obs) num [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a2_zlib_obs, a2_exp)) > > ## > ## array: case-3 > ## > a3_exp <- array(c(TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, + TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, + FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, + FALSE, TRUE), c(5L, 5L)) > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a3_exp), filename = filename, compression = FALSE, + version = "MAT5") > a3_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a3_obs) logi [1:5, 1:5] TRUE TRUE TRUE TRUE TRUE FALSE ... > stopifnot(identical(a3_obs, a3_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a3_exp), filename = filename, compression = TRUE, + version = "MAT5") > a3_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a3_zlib_obs) logi [1:5, 1:5] TRUE TRUE TRUE TRUE TRUE FALSE ... > stopifnot(identical(a3_zlib_obs, a3_exp)) > > ## > ## array: case-4 > ## > a4_exp <- array(seq_len(32^3), c(32, 32, 32)) > storage.mode(a4_exp) <- "double" > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a4_exp), filename = filename, compression = FALSE, + version = "MAT5") > a4_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a4_obs) num [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a4_obs, a4_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a4_exp), filename = filename, compression = TRUE, + version = "MAT5") > a4_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a4_zlib_obs) num [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a4_zlib_obs, a4_exp)) > > ## > ## array: case-5 > ## > a5_exp <- array(seq_len(32^3), c(32, 32, 32)) > storage.mode(a5_exp) <- "integer" > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a5_exp), filename = filename, compression = FALSE, + version = "MAT5") > a5_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a5_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a5_obs, a5_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a5_exp), filename = filename, compression = TRUE, + version = "MAT5") > a5_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a5_zlib_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a5_zlib_obs, a5_exp)) > > ## > ## array: case-6 > ## > a6_exp <- array(c(seq_len(32767), 32767), c(32, 32, 32)) > storage.mode(a6_exp) <- "integer" > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a6_exp), filename = filename, compression = FALSE, + version = "MAT5") > a6_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a6_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a6_obs, a6_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a6_exp), filename = filename, compression = TRUE, + version = "MAT5") > a6_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a6_zlib_obs) int [1:32, 1:32, 1:32] 1 2 3 4 5 6 7 8 9 10 ... > stopifnot(identical(a6_zlib_obs, a6_exp)) > > ## > ## array: case-7 > ## > a7_exp <- array(complex(real = seq(1, 2 * 32^3, 2), + imaginary = seq(2, 2 * 32^3, 2)), + c(32, 32, 32)) > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a7_exp), filename = filename, compression = FALSE, + version = "MAT5") > a7_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a7_obs) cplx [1:32, 1:32, 1:32] 1+2i 3+4i 5+6i ... > stopifnot(identical(a7_obs, a7_exp)) > > ## Run the same test with compression > filename <- tempfile(fileext = ".mat") > write.mat(list(a = a7_exp), filename = filename, compression = TRUE, + version = "MAT5") > a7_zlib_obs <- read.mat(filename)[["a"]] > unlink(filename) > str(a7_zlib_obs) cplx [1:32, 1:32, 1:32] 1+2i 3+4i 5+6i ... > stopifnot(identical(a7_zlib_obs, a7_exp)) > > proc.time() user system elapsed 0.98 0.12 1.09