Skip to content

Commit

Permalink
Clean up calls to saveObject to save external seeds in storeDelayedOb…
Browse files Browse the repository at this point in the history
…ject.

- We switch to altSaveObject (altReadObject, for reloadDelayedObject)
  to ensure that we respect application-level overrides.
- We add an external.save.args= option to handle additional arguments
  from saveObject,DelayedArray-method. This avoids conflicts between
  arguments of saveObject and storeDelayedObject methods.
  • Loading branch information
LTLA committed Sep 3, 2024
1 parent 283382a commit 3157c53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions R/saveDelayedArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ setMethod("saveObject", "DelayedArray", function(x, path, DelayedArray.dispatch.

fhandle <- H5Fcreate(file.path(path, "array.h5"))
on.exit(H5Fclose(fhandle), add=TRUE, after=FALSE)

if (!("external.save.args" %in% names(DelayedArray.store.args))) {
DelayedArray.store.args$external.save.args <- list(...)
}
do.call(storeDelayedObject, c(list(x@seed, handle=fhandle, name="delayed_array"), DelayedArray.store.args))

ghandle <- H5Gopen(fhandle, "delayed_array")
Expand Down
8 changes: 5 additions & 3 deletions R/storeDelayedObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' keep the old or new function, or throw an error.
#' @param save.external.array Logical scalar indicating whether to save an array-like seed as an external seed,
#' even if a dedicated \code{storeDelayedObject} method is available.
#' @param external.save.args Named list of further arguments to pass to \code{\link{altSaveObject}} when saving an external seed.
#' @param external.dedup.session Session object created by \code{createExternalSeedDedupSession}.
#' @param external.dedup.action String specifying the deduplication method to use.
#'
Expand All @@ -46,7 +47,7 @@
#' @section External seeds:
#' Whenever \code{storeDelayedObject} encounters a delayed operation or array-like seed for which it has no methods,
#' the ANY method will save the delayed object as an \dQuote{external seed}.
#' The array is saved via \code{\link{saveObject}} into a \code{seeds} directory next to the file corresponding to \code{handle}.
#' The array is saved via \code{\link{altSaveObject}} into a \code{seeds} directory next to the file associated with \code{handle}.
#' A reference to this external location is then stored in the \code{name} group inside \code{handle}.
#'
#' Users can force this behavior for all array-like seeds by passing \code{save.external.array=TRUE} in the \code{...} arguments of \code{storeDelayedObject}.
Expand Down Expand Up @@ -1092,6 +1093,7 @@ setMethod("storeDelayedObject", "ANY", function(
handle,
name,
version=package_version("1.1"),
external.save.args=list(),
external.dedup.session=NULL,
external.dedup.action=c("link", "copy", "symlink", "relsymlink"),
...)
Expand Down Expand Up @@ -1148,7 +1150,7 @@ setMethod("storeDelayedObject", "ANY", function(

dedup.path <- check_external_seed_in_dedup_session(x, session=external.dedup.session)
if (is.null(dedup.path)) {
saveObject(x, output, ...)
do.call(altSaveObject, c(list(x=x, path=output), external.save.args))
} else {
clone_duplicate(dedup.path, output, action=match.arg(external.dedup.action))
}
Expand All @@ -1163,7 +1165,7 @@ setMethod("storeDelayedObject", "ANY", function(
#' @import alabaster.base rhdf5 DelayedArray
chihaya.registry$array[["custom takane seed array"]] <- function(handle, version, custom.takane.realize=FALSE, ...) {
index <- h5_read_vector(handle, "index")
out <- readObject(file.path(dirname(H5Fget_name(handle)), "seeds", index), ...)
out <- altReadObject(file.path(dirname(H5Fget_name(handle)), "seeds", index), ...)

if (custom.takane.realize) {
if (is_sparse(out)) {
Expand Down
5 changes: 4 additions & 1 deletion man/storeDelayedObject.Rd

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

0 comments on commit 3157c53

Please sign in to comment.