Skip to content

Commit

Permalink
Exported LazyH5
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Jan 9, 2025
1 parent d7ee145 commit 34dda1c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -27,6 +27,7 @@ Imports:
fst (>= 0.9.0),
gifti (>= 0.8.0),
grDevices,
hdf5r,
jsonlite,
oro.nifti,
R.matlab (>= 3.7.0),
Expand All @@ -35,7 +36,6 @@ Imports:
rpyANTs (>= 0.0.3),
stringr,
utils,
hdf5r,
yaml
Suggests:
reticulate,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 0 additions & 22 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
14 changes: 11 additions & 3 deletions R/hdf5-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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]]
Expand All @@ -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
Expand Down
35 changes: 24 additions & 11 deletions R/py-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 34dda1c

Please sign in to comment.