-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
GCP integrations
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
resources_gcp_init <- function( | ||
bucket = NULL, | ||
prefix = path_objects_dir_cloud(), | ||
verbose = FALSE | ||
) { | ||
resources_gcp_new( | ||
bucket = bucket, | ||
prefix = prefix, | ||
verbose = verbose | ||
) | ||
} | ||
|
||
resources_gcp_new <- function( | ||
bucket = NULL, | ||
prefix = NULL, | ||
verbose = FALSE | ||
) { | ||
force(bucket) | ||
force(prefix) | ||
force(verbose) | ||
enclass(environment(), c("tar_resources_gcp", "tar_resources")) | ||
} | ||
|
||
#' @export | ||
resources_validate.tar_resources_gcp <- function(resources) { | ||
tar_assert_scalar(resources$bucket %|||% "bucket") | ||
tar_assert_chr(resources$bucket %|||% "bucket") | ||
tar_assert_nzchar(resources$bucket %|||% "bucket") | ||
tar_assert_scalar(resources$prefix) | ||
tar_assert_chr(resources$prefix) | ||
tar_assert_nzchar(resources$prefix) | ||
tar_assert_lgl(resources$verbose) | ||
tar_assert_scalar(resources$verbose) | ||
} | ||
|
||
#' @export | ||
print.tar_resources_gcp <- function(x, ...) { | ||
cat( | ||
"<tar_resources_gcp>\n ", | ||
paste0(paste_list(as.list(x)), collapse = "\n ") | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#' @title Target resources: Google Cloud Platform storage formats | ||
#' @export | ||
#' @family resources | ||
#' @description Create the `gcp` argument of `tar_resources()` | ||
#' to specify optional settings to gcp storage formats. | ||
#' See the `format` argument of [tar_target()] for details. | ||
#' @inheritSection tar_resources Resources | ||
#' @return Object of class `"tar_resources_gcp"`, to be supplied | ||
#' to the `gcp` argument of `tar_resources()`. | ||
#' @param bucket Character of length 1, name of an existing | ||
#' gcp bucket to upload and download the return values | ||
#' of the affected targets during the pipeline. | ||
#' @param prefix Character of length 1, "directory path" | ||
#' in the S3 bucket where the target return values are stored. | ||
#' @param verbose Whether to have feedback on the GCS upload process | ||
#' @examples | ||
#' # Somewhere in you target script file (usually _targets.R): | ||
#' if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { | ||
#' tar_target( | ||
#' name, | ||
#' command(), | ||
#' format = "gcp_qs", | ||
#' resources = tar_resources( | ||
#' gcp = tar_resources_gcp(bucket = "yourbucketname"), | ||
#' qs = tar_resources_qs(preset = "fast") | ||
#' ) | ||
#' ) | ||
#' } | ||
tar_resources_gcp <- function( | ||
bucket, | ||
prefix = targets::path_objects_dir_cloud(), | ||
verbose = FALSE | ||
) { | ||
out <- resources_gcp_init( | ||
bucket = bucket, | ||
prefix = prefix, | ||
verbose = verbose | ||
) | ||
resources_validate(out) | ||
out | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
tar_test("create tar_resources_gcp object", { | ||
x <- resources_gcp_init(bucket = "bucket_name") | ||
expect_silent(resources_validate(x)) | ||
}) | ||
|
||
tar_test("prohibit empty tar_resources_gcp object", { | ||
x <- resources_gcp_init(bucket = "", prefix = NULL) | ||
expect_error(resources_validate(x), class = "tar_condition_validate") | ||
}) | ||
|
||
tar_test("print tar_resources_aws object", { | ||
x <- resources_gcp_init(bucket = "bucket_name") | ||
out <- utils::capture.output(print(x)) | ||
expect_true(any(grepl("tar_resources_gcp", out))) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tar_test("tar_resources_gcp()", { | ||
out <- tar_resources_gcp(bucket = "bucket123") | ||
expect_equal(out$bucket, "bucket123") | ||
expect_null(out$region) | ||
expect_silent(resources_validate(out)) | ||
}) |