Skip to content

Commit

Permalink
io_read_mat examples runs under interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Sep 9, 2024
1 parent fe32ae4 commit 53fa43a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
^docs$
^pkgdown$
^cran-comments\.md$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 0.0.1
Date: 2024-09-09 04:24:18 UTC
SHA: fe32ae4e4f7c9d5917c8ecd81c2746bf012804b4
29 changes: 22 additions & 7 deletions R/mat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#'
#' # ---- Matlab .mat --------------------------------------------------------
#'
#' if(interactive()) {
#'
#' f <- tempfile(fileext = ".mat")
#'
#' x <- list(a = 1L, b = 2.3, c = "a", d = 1+1i)
Expand All @@ -16,8 +18,6 @@
#'
#' io_read_mat(f)
#'
#' \dontrun{
#'
#' # require setting up Python environment
#'
#' io_read_mat(f, method = "pymatreader")
Expand All @@ -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"),
Expand Down Expand Up @@ -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.")
Expand All @@ -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)
}
10 changes: 5 additions & 5 deletions man/low-level-read-write.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53fa43a

Please sign in to comment.