From d78a051d5ce436b778cc096de1e8cad827422624 Mon Sep 17 00:00:00 2001 From: Eliot McIntire Date: Thu, 19 Dec 2024 17:34:58 -0800 Subject: [PATCH] .callingEnv --- R/download.R | 33 ++++++++++++++++++--------------- R/preProcess.R | 18 ++++++++++-------- R/prepInputs.R | 2 +- man/downloadFile.Rd | 4 ++++ man/downloadRemote.Rd | 4 ++++ man/preProcess.Rd | 4 ++++ 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/R/download.R b/R/download.R index 44e07306a..dbce2b651 100755 --- a/R/download.R +++ b/R/download.R @@ -34,16 +34,16 @@ downloadFile <- function(archive, targetFile, neededFiles, overwrite = getOption("reproducible.overwrite", TRUE), alsoExtract = "similar", verbose = getOption("reproducible.verbose", 1), - purge = FALSE, .tempPath, # .callingEnv, + purge = FALSE, .tempPath, .callingEnv, ...) { dots <- list(...) - if (is.null(dots$.callingEnv)) { - .callingEnv <- parent.frame() - } else { - .callingEnv <- dots$.callingEnv - dots$.callingEnv <- NULL - } + # if (is.null(dots$.callingEnv)) { + # .callingEnv <- parent.frame() + # } else { + # .callingEnv <- dots$.callingEnv + # dots$.callingEnv <- NULL + # } # browser(expr = exists("._downloadFile_1")) if (missing(.tempPath)) { @@ -142,7 +142,7 @@ downloadFile <- function(archive, targetFile, neededFiles, alsoExtract = alsoExtract, verbose = verbose, .tempPath = .tempPath, - # .callingEnv = .callingEnv, + .callingEnv = .callingEnv, ... ) , error = function(e) { @@ -641,15 +641,15 @@ downloadRemote <- function(url, archive, targetFile, checkSums, dlFun = NULL, fileToDownload, messSkipDownload, destinationPath, overwrite, needChecksums, .tempPath, preDigest, alsoExtract = "similar", - verbose = getOption("reproducible.verbose", 1), # .callingEnv = parent.frame(), + verbose = getOption("reproducible.verbose", 1), .callingEnv = parent.frame(), ...) { dots <- list(...) - if (is.null(dots$.callingEnv)) { - .callingEnv <- parent.frame() - } else { - .callingEnv <- dots$.callingEnv - dots$.callingEnv <- NULL - } + # if (is.null(dots$.callingEnv)) { + # .callingEnv <- parent.frame() + # } else { + # .callingEnv <- dots$.callingEnv + # dots$.callingEnv <- NULL + # } noTargetFile <- is.null(targetFile) || length(targetFile) == 0 if (missing(.tempPath)) { @@ -713,6 +713,9 @@ downloadRemote <- function(url, archive, targetFile, checkSums, dlFun = NULL, } if (!is.call(dlFun)) { + formsDlFun <- formalArgs(dlFun) + argsKeep <- intersect(formsDlFun, names(args)) + args <- args[argsKeep] out <- do.call(dlFun, args = args) } diff --git a/R/preProcess.R b/R/preProcess.R index 4cd285309..11b4769ea 100644 --- a/R/preProcess.R +++ b/R/preProcess.R @@ -146,6 +146,8 @@ preProcessParams <- function(n = NULL) { #' `fun` (the function to be used to load the `preProcess`ed object from disk), #' and `targetFilePath` (the fully qualified path to the `targetFile`). #' +#' @param .callingEnv The environment where the function was called from. Used to find +#' objects, if necessary. #' @section Combinations of `targetFile`, `url`, `archive`, `alsoExtract`: #' #' Use `preProcessParams()` for a table describing various parameter combinations and their @@ -169,7 +171,7 @@ preProcess <- function(targetFile = NULL, url = NULL, archive = NULL, alsoExtrac overwrite = getOption("reproducible.overwrite", FALSE), purge = FALSE, verbose = getOption("reproducible.verbose", 1), - .tempPath, # .callingEnv = parent.frame(), + .tempPath, .callingEnv = parent.frame(), ...) { st <- Sys.time() messagePreProcess("Running `preProcess`", verbose = verbose, verboseLevel = 0) @@ -192,12 +194,12 @@ preProcess <- function(targetFile = NULL, url = NULL, archive = NULL, alsoExtrac } dots <- list(...) - if (is.null(dots$.callingEnv)) { - .callingEnv <- parent.frame() - } else { - .callingEnv <- dots$.callingEnv - dots$.callingEnv <- NULL - } + # if (is.null(dots$.callingEnv)) { + # .callingEnv <- parent.frame() + # } else { + # .callingEnv <- dots$.callingEnv + # dots$.callingEnv <- NULL + # } fun <- .checkFunInDots(fun = fun, dots = dots) dots <- .checkDeprecated(dots, verbose = verbose) @@ -417,7 +419,7 @@ preProcess <- function(targetFile = NULL, url = NULL, archive = NULL, alsoExtrac overwrite = overwrite, purge = purge, # may need to try purging again if no target, alsoExtract = alsoExtract, # archive or alsoExtract were known yet - verbose = verbose, .tempPath = .tempPath, # .callingEnv = .callingEnv, + verbose = verbose, .tempPath = .tempPath, .callingEnv = .callingEnv, ... ) diff --git a/R/prepInputs.R b/R/prepInputs.R index 5cfe1e4d2..ebe0420d6 100644 --- a/R/prepInputs.R +++ b/R/prepInputs.R @@ -375,7 +375,7 @@ prepInputs <- function(targetFile = NULL, url = NULL, archive = NULL, alsoExtrac useCache = useCache, .tempPath = .tempPath, verbose = verbose, - .callingEnv = .callingEnv, + # .callingEnv = .callingEnv, ... ) diff --git a/man/downloadFile.Rd b/man/downloadFile.Rd index 602236ff9..15dd02863 100644 --- a/man/downloadFile.Rd +++ b/man/downloadFile.Rd @@ -21,6 +21,7 @@ downloadFile( verbose = getOption("reproducible.verbose", 1), purge = FALSE, .tempPath, + .callingEnv, ... ) } @@ -105,6 +106,9 @@ option, e.g., \verb{options('reproducible.verbose' = 0) to reduce to minimal}} \item{.tempPath}{Optional temporary path for internal file intermediate steps. Will be cleared on.exit from this function.} +\item{.callingEnv}{The environment where the function was called from. Used to find +objects, if necessary.} + \item{...}{Passed to \code{dlFun}. Still experimental. Can be e.g., \code{type} for google docs.} } \value{ diff --git a/man/downloadRemote.Rd b/man/downloadRemote.Rd index d7e747414..34d8baadf 100644 --- a/man/downloadRemote.Rd +++ b/man/downloadRemote.Rd @@ -19,6 +19,7 @@ downloadRemote( preDigest, alsoExtract = "similar", verbose = getOption("reproducible.verbose", 1), + .callingEnv = parent.frame(), ... ) } @@ -90,6 +91,9 @@ Default is 1. Above 3 will output much more information about the internals of Caching, which may help diagnose Caching challenges. Can set globally with an option, e.g., \verb{options('reproducible.verbose' = 0) to reduce to minimal}} +\item{.callingEnv}{The environment where the function was called from. Used to find +objects, if necessary.} + \item{...}{Additional arguments passed to \code{\link[=postProcess]{postProcess()}} and \code{\link[=Cache]{Cache()}}. Since \code{...} is passed to \code{\link[=postProcess]{postProcess()}}, these will diff --git a/man/preProcess.Rd b/man/preProcess.Rd index 4a7d094ce..29effd7b9 100644 --- a/man/preProcess.Rd +++ b/man/preProcess.Rd @@ -20,6 +20,7 @@ preProcess( purge = FALSE, verbose = getOption("reproducible.verbose", 1), .tempPath, + .callingEnv = parent.frame(), ... ) } @@ -104,6 +105,9 @@ option, e.g., \verb{options('reproducible.verbose' = 0) to reduce to minimal}} \item{.tempPath}{Optional temporary path for internal file intermediate steps. Will be cleared on.exit from this function.} +\item{.callingEnv}{The environment where the function was called from. Used to find +objects, if necessary.} + \item{...}{Additional arguments passed to \code{\link[=postProcess]{postProcess()}} and \code{\link[=Cache]{Cache()}}. Since \code{...} is passed to \code{\link[=postProcess]{postProcess()}}, these will