Skip to content

Commit

Permalink
.callingEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliot McIntire committed Dec 20, 2024
1 parent f0ccc2d commit d78a051
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
33 changes: 18 additions & 15 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -142,7 +142,7 @@ downloadFile <- function(archive, targetFile, neededFiles,
alsoExtract = alsoExtract,
verbose = verbose,
.tempPath = .tempPath,
# .callingEnv = .callingEnv,
.callingEnv = .callingEnv,
...
)
, error = function(e) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 10 additions & 8 deletions R/preProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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,
...
)

Expand Down
2 changes: 1 addition & 1 deletion R/prepInputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ prepInputs <- function(targetFile = NULL, url = NULL, archive = NULL, alsoExtrac
useCache = useCache,
.tempPath = .tempPath,
verbose = verbose,
.callingEnv = .callingEnv,
# .callingEnv = .callingEnv,
...
)

Expand Down
4 changes: 4 additions & 0 deletions man/downloadFile.Rd

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

4 changes: 4 additions & 0 deletions man/downloadRemote.Rd

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

4 changes: 4 additions & 0 deletions man/preProcess.Rd

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

0 comments on commit d78a051

Please sign in to comment.