From 34dda1cc0dc84bcf21f329a6eaf3f0eb21ef3036 Mon Sep 17 00:00:00 2001 From: dipterix Date: Thu, 9 Jan 2025 17:12:42 -0500 Subject: [PATCH] Exported `LazyH5` --- DESCRIPTION | 4 ++-- NAMESPACE | 1 + R/aaa.R | 22 ---------------------- R/hdf5-class.R | 14 +++++++++++--- R/py-setup.R | 35 ++++++++++++++++++++++++----------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 807acd8..02144e1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ieegio Title: File IO for Intracranial Electroencephalography -Version: 0.0.2.9008 +Version: 0.0.2.9009 Language: en-US Encoding: UTF-8 Authors@R: @@ -27,6 +27,7 @@ Imports: fst (>= 0.9.0), gifti (>= 0.8.0), grDevices, + hdf5r, jsonlite, oro.nifti, R.matlab (>= 3.7.0), @@ -35,7 +36,6 @@ Imports: rpyANTs (>= 0.0.3), stringr, utils, - hdf5r, yaml Suggests: reticulate, diff --git a/NAMESPACE b/NAMESPACE index e6267cf..0ceda12 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ S3method(print,ieegio_get_channel) S3method(print,ieegio_surface) S3method(print,ieegio_volume) S3method(print,nwb.proxy) +export(LazyH5) export(as_ieegio_volume) export(burn_volume) export(ieegio_sample_data) diff --git a/R/aaa.R b/R/aaa.R index f69c45a..c802e7d 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -136,28 +136,6 @@ ensure_r_package <- function(pkg, ...) { stop("R package `", pkg, "` is missing. Please manually install them in interactive mode.") } -ensure_py_package <- function(pkg, method = c("pip", "conda"), ...) { - if(!file.exists(rpymat::env_path())) { - if(package_installed("ravemanager")) { - ravemanager <- asNamespace("ravemanager") - ravemanager$configure_python() - } else { - rpyANTs::install_ants() - } - } - pkg_list <- rpymat::list_pkgs() - if(pkg %in% pkg_list$package) { - return(invisible()) - } - method <- match.arg(method) - if (method == "pip") { - rpymat::add_packages(pkg, pip = TRUE) - } else { - rpymat::add_packages(pkg) - } - return(invisible()) -} - ensure_package <- function(pkg, ..., lang = c("r", "python"), need_interactive = TRUE) { lang <- match.arg(lang) if(need_interactive && !interactive()) { diff --git a/R/hdf5-class.R b/R/hdf5-class.R index 2ee4d97..35af336 100644 --- a/R/hdf5-class.R +++ b/R/hdf5-class.R @@ -88,6 +88,7 @@ h5FileValid <- function(filename){ #' @title Lazy 'HDF5' file loader #' @description provides hybrid data structure for 'HDF5' file +#' @export LazyH5 <- R6::R6Class( classname = 'LazyH5', portable = TRUE, @@ -218,6 +219,13 @@ LazyH5 <- R6::R6Class( storage.mode(x) <- "double" } }, + "character" = { + x <- as.character(x) + }, + "string" = { + x <- as.character(x) + ctype <- "character" + }, { storage.mode(x) <- ctype } @@ -285,7 +293,7 @@ LazyH5 <- R6::R6Class( if(!ptr$path_valid(path = nm)){ ptr <- ptr$create_group(i) if(!self$quiet){ - cat('{private$file} => {nm} (Group Created)\n') + cat(sprintf('%s => %s (Group Created)\n', private$file, nm)) } }else{ ptr <- ptr[[i]] @@ -297,13 +305,13 @@ LazyH5 <- R6::R6Class( if(ptr$path_valid(path = nm)){ # dataset exists, unlink first if(!self$quiet){ - cat('{private$file} => {private$name} (Dataset Removed)\n') + cat(sprintf('%s => %s (Dataset Removed)\n', private$file, nm)) } ptr$link_delete(nm) } # new create if(!self$quiet){ - cat('{private$file} => {private$name} (Dataset Created)\n') + cat(sprintf('%s => %s (Dataset Created)\n', private$file, nm)) } if(missing(robj)){ robj <- NA diff --git a/R/py-setup.R b/R/py-setup.R index 8615c20..ac7483f 100644 --- a/R/py-setup.R +++ b/R/py-setup.R @@ -86,18 +86,31 @@ validate_python <- function(verbose = TRUE) { ) }) -ensure_py_package <- function(packages, python_ver = "auto", ...) { - if(!dir.exists(rpymat::env_path())) { - standalone <- !file.exists(rpymat::conda_bin()) - rpymat::configure_conda(python_ver = python_ver, force = TRUE, standalone = standalone) - } - rpymat::ensure_rpymat(verbose = FALSE) - installed_pkgs_tbl <- rpymat::list_pkgs() - packages <- packages[!packages %in% installed_pkgs_tbl$package] - if(length(packages)) { - rpymat::add_packages(packages, ...) +ensure_py_package <- local({ + + installed_pkgs_tbl <- NULL + + function(packages, python_ver = "auto", ...) { + if(!dir.exists(rpymat::env_path())) { + standalone <- !file.exists(rpymat::conda_bin()) + rpymat::configure_conda(python_ver = python_ver, force = TRUE, standalone = standalone) + } + rpymat::ensure_rpymat(verbose = FALSE) + + if(is.null(installed_pkgs_tbl) || !is.data.frame(installed_pkgs_tbl) || !all(packages %in% installed_pkgs_tbl$package)) { + installed_pkgs_tbl <<- rpymat::list_pkgs() + } + + packages <- packages[!packages %in% installed_pkgs_tbl$package] + + if(length(packages)) { + rpymat::add_packages(packages, ...) + installed_pkgs_tbl <<- rpymat::list_pkgs() + } + + invisible() } -} +}) import_py_module <- function(name, package = name, convert = FALSE) { rpymat::ensure_rpymat(verbose = FALSE, cache = TRUE)