diff --git a/DESCRIPTION b/DESCRIPTION index a7bdd2bbee6cfae86e2723387005174816e77ed7..fce86c714a68100952f8dae598c90c288f591231 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,7 @@ Imports: abind, bigmemory, future, - multiApply (>= 2.0.0), + multiApply (>= 2.1.1), parallel Suggests: easyNCDF, diff --git a/R/Step.R b/R/Step.R index d08595ab4adcb46105de7f381b31716b3bca8aa2..1f54d0838a217f646bd5201ead72636e4c1349df 100644 --- a/R/Step.R +++ b/R/Step.R @@ -1,4 +1,5 @@ -Step <- function(fun, target_dims, output_dims) { +Step <- function(fun, target_dims, output_dims, + use_libraries = NULL, use_attributes = NULL) { # Check fun if (!is.function(fun)) { stop("Parameter 'fun' must be a function.") @@ -42,8 +43,39 @@ Step <- function(fun, target_dims, output_dims) { } } + # Check use_libraries + if (!is.null(use_libraries)) { + if (!is.character(use_libraries)) { + stop("Parameter 'use_libraries' must be a vector of character ", + "strings.") + } + } + + # Check use_attributes + if (!is.null(use_attributes)) { + raise_error <- FALSE + if (!is.list(use_attributes)) { + raise_error <- TRUE + } + if (!all(sapply(use_attributes, + function(x) { + is.character(x) || + (is.list(x) && all(sapply(x, is.character))) + }))) { + raise_error <- TRUE + } + if (raise_error) { + stop("Parameter 'use_attributes' must be a list of vectors of ", + "character strings or of lists of vectors of character ", + "strings.") + } + } + attr(fun, 'TargetDims') <- target_dims attr(fun, 'OutputDims') <- output_dims + attr(fun, 'UseLibraries') <- use_libraries + attr(fun, 'UseAttributes') <- use_attributes + # TODO: Add provenance info class(fun) <- 'startR_step_fun' diff --git a/inst/chunking/load_process_save_chunk.R b/inst/chunking/load_process_save_chunk.R index c552aa2e2b29bbd1893e01a496cf7f3fabcd0283..f2834da320881275acefe95c0c3e3af658b8f6be 100644 --- a/inst/chunking/load_process_save_chunk.R +++ b/inst/chunking/load_process_save_chunk.R @@ -76,13 +76,20 @@ t_end_load <- Sys.time() t_load <- as.numeric(difftime(t_end_load, t_begin_load, units = 'secs')) t_begin_compute <- Sys.time() +if (!is.null(attr(fun, 'UseLibraries'))) { + for (i in seq_along(attr(fun, 'UseLibraries'))) { + require(attr(fun, 'UseLibraries')[i]) + } +} Apply <- multiApply::Apply res <- do.call("Apply", c( list(data, target_dims = attr(fun, 'TargetDims'), fun = fun, - output_dims = attr(fun, 'OutputDims'), + output_dims = attr(fun, 'OutputDims'), + use_attributes = attr(fun, 'UseAttributes'), + extra_info = list(chunk_indices = as.integer(chunk_indices)), ncores = threads_compute), params )