-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
306 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' @title Download a workspace from the cloud. | ||
#' @export | ||
#' @family debug | ||
#' @description Download a workspace file from the cloud | ||
#' so it can be loaded with [tar_workspace()]. | ||
#' @details If `tar_option_get("repository_meta")` is `"aws"` or `"gcp"`, then | ||
#' [tar_make()] uploads workspaces to the bucket and prefix provided. | ||
#' Download one of these workspaces with [tar_workspace_download()]. | ||
#' Downloaded workspaces can be loaded the usual way with | ||
#' [tar_workspace()], and you should see them in | ||
#' character vector returned by [tar_workspaces()]. | ||
#' @return `NULL` (invisibly). Returns an error if the workspace | ||
#' cannot be downloaded. | ||
#' @inheritParams tar_validate | ||
#' @param name Symbol, name of the target whose workspace to download. | ||
#' @param script Character string, file path to the `_targets.R` file | ||
#' defining the pipeline. Must be configured with the right `aws` | ||
#' and `repository_meta` options (in [tar_option_set()]) | ||
#' to support downloading workspaces from the cloud. | ||
#' @examples | ||
#' if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN | ||
#' tar_dir({ # tar_dir() runs code from a temp dir for CRAN. | ||
#' tmp <- sample(1) | ||
#' tar_script({ | ||
#' library(targets) | ||
#' library(tarchetypes) | ||
#' tar_option_set( | ||
#' tar_option_set( | ||
#' resources = tar_resources( | ||
#' tar_resources_aws( | ||
#' bucket = "YOUR_AWS_BUCKET", | ||
#' prefix = "_targets" | ||
#' ) | ||
#' ), | ||
#' repository = "aws", | ||
#' repository_meta = "aws" | ||
#' ) | ||
#' f <- function() stop("this is an error and thus triggers a workspace") | ||
#' list( | ||
#' tar_target(x, f()), | ||
#' ) | ||
#' }, ask = FALSE) | ||
#' # The following code throws an error for demonstration purposes. | ||
#' try(tar_make()) | ||
#' # Say the workspace file for target x does not exist. | ||
#' unlink("_targets/workspaces/x") | ||
#' file.exists("_targets/workspaces/x") | ||
#' # We can download it with tar_workspace_download() | ||
#' tar_workspace_download(x) | ||
#' file.exists("_targets/workspaces/x") | ||
#' tar_workspace(x) | ||
#' }) | ||
#' } | ||
tar_workspace_download <- function( | ||
name, | ||
script = targets::tar_config_get("script"), | ||
store = targets::tar_config_get("store") | ||
) { | ||
name <- tar_deparse_language(substitute(name)) | ||
tar_assert_chr(name) | ||
tar_assert_scalar(name) | ||
tar_assert_nzchar(name) | ||
tar_assert_scalar(store) | ||
tar_assert_chr(store) | ||
tar_assert_nzchar(store) | ||
options <- tar_script_options(script = script) | ||
old_repository_meta <- tar_options$get_repository_meta() | ||
old_resources <- tar_options$get_resources() | ||
on.exit({ | ||
tar_options$set_repository_meta(old_repository_meta) | ||
tar_options$set_resources(old_resources) | ||
}) | ||
tar_options$set_repository_meta(options$repository_meta) | ||
tar_options$set_resources(options$resources) | ||
tar_assert_not_in( | ||
x = options$repository_meta, | ||
choices = "local", | ||
msg = paste( | ||
"tar_workspace_download() is not supported for", | ||
"tar_option_get(\"repository_meta\") == \"local\"." | ||
) | ||
) | ||
database_meta(path_store = store)$download_workspace(name, store) | ||
invisible() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.