diff --git a/.Rbuildignore b/.Rbuildignore index fce6713..eda25cf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,3 +8,4 @@ ^docs$ ^pkgdown$ ^cran-comments\.md$ +^CRAN-SUBMISSION$ diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000..5deb649 --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 0.0.1 +Date: 2024-09-09 04:24:18 UTC +SHA: fe32ae4e4f7c9d5917c8ecd81c2746bf012804b4 diff --git a/R/mat.R b/R/mat.R index 23689df..43da589 100644 --- a/R/mat.R +++ b/R/mat.R @@ -7,6 +7,8 @@ #' #' # ---- Matlab .mat -------------------------------------------------------- #' +#' if(interactive()) { +#' #' f <- tempfile(fileext = ".mat") #' #' x <- list(a = 1L, b = 2.3, c = "a", d = 1+1i) @@ -16,8 +18,6 @@ #' #' io_read_mat(f) #' -#' \dontrun{ -#' #' # require setting up Python environment #' #' io_read_mat(f, method = "pymatreader") @@ -26,11 +26,11 @@ #' sample_data <- ieegio_sample_data("mat_v73.mat") #' io_read_mat(sample_data) #' +#' # clean up +#' unlink(f) #' #' } #' -#' # clean up -#' unlink(f) #' #' @export io_read_mat <- function(con, method = c("auto", "R.matlab", "pymatreader", "mat73"), @@ -197,7 +197,9 @@ io_read_mat <- function(con, method = c("auto", "R.matlab", "pymatreader", "mat7 #' @rdname low-level-read-write #' @export -io_write_mat <- function(x, con, ...) { +io_write_mat <- function(x, con, method = c("R.matlab", "scipy"), ...) { + + method <- match.arg(method) if(!is.list(x)) { stop("`write_mat`: `x` must be a named list.") @@ -213,7 +215,20 @@ io_write_mat <- function(x, con, ...) { stop("`write_mat`: `x` must NOT contain the following reserved names: ", paste(sQuote(reserved), collapse = ", ")) } - args <- c( list( con = con ), x ) + con <- normalizePath(con, winslash = "/", mustWork = FALSE) + + switch( + method, + "R.matlab" = { + args <- c( list( con = con ), x ) + + do.call(R.matlab::writeMat, args) + }, + "scipy" = { + scipy_io <- import_py_module("scipy.io", "scipy") + scipy_io$savemat(con, x) + } + ) - do.call(R.matlab::writeMat, args) + invisible(con) } diff --git a/man/low-level-read-write.Rd b/man/low-level-read-write.Rd index be28c17..4879631 100644 --- a/man/low-level-read-write.Rd +++ b/man/low-level-read-write.Rd @@ -44,7 +44,7 @@ io_read_mat( ... ) -io_write_mat(x, con, ...) +io_write_mat(x, con, method = c("R.matlab", "scipy"), ...) io_read_yaml(con, ...) @@ -159,6 +159,8 @@ unlink(f) # ---- Matlab .mat -------------------------------------------------------- +if(interactive()) { + f <- tempfile(fileext = ".mat") x <- list(a = 1L, b = 2.3, c = "a", d = 1+1i) @@ -168,8 +170,6 @@ io_write_mat(x, f) io_read_mat(f) -\dontrun{ - # require setting up Python environment io_read_mat(f, method = "pymatreader") @@ -178,11 +178,11 @@ io_read_mat(f, method = "pymatreader") sample_data <- ieegio_sample_data("mat_v73.mat") io_read_mat(sample_data) +# clean up +unlink(f) } -# clean up -unlink(f) # ---- yaml ---------------------------------------------------------------