diff --git a/NAMESPACE b/NAMESPACE index ca9071c..a7b10dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,9 @@ export(check_nzchar) export(check_scalar_type) export(check_that) export(check_vec) +export(cst_error_msg) +export(ct_error_msg) +export(cv_error_msg) export(generate_resource) export(get_auth_token) export(get_container) diff --git a/R/get_container.R b/R/get_container.R index 4bbd257..31a5d3d 100644 --- a/R/get_container.R +++ b/R/get_container.R @@ -21,12 +21,18 @@ get_container <- function( endpoint_url = NULL, ... ) { - msg <- paste0( + msg1 <- paste0( "{.var container_name} is empty. ", "Did you forget to set an environment variable?" ) + msg2 <- paste0( + "{.var endpoint_url} is empty. ", + "Did you forget to set an environment variable?" + ) container_name <- (container_name %||% check_envvar("AZ_CONTAINER")) |> - check_nzchar(msg) + check_nzchar(msg1) + endpoint_url <- (endpoint_url %||% check_envvar("AZ_STORAGE_EP")) |> + check_nzchar(msg2) token <- token %||% get_auth_token(...) get_azure_endpoint(token, endpoint_url) |> diff --git a/R/helpers.R b/R/helpers.R index c5d5b88..18afcd0 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -21,7 +21,7 @@ check_that <- function(x, predicate, message, pf = parent.frame()) { } -#' @keywords internal +#' @export ct_error_msg <- \(text) paste0("{.fn check_that}: ", text) #' An alternative to stopifnot/assert_that etc @@ -63,7 +63,7 @@ check_vec <- function( } } -#' @keywords internal +#' @export cv_error_msg <- \(text) paste0("{.fn check_vec}: ", text) @@ -108,7 +108,7 @@ check_scalar_type <- function( } } -#' @keywords internal +#' @export cst_error_msg <- \(text) paste0("{.fn check_scalar_type}: ", text) diff --git a/R/read_azure_files.R b/R/read_azure_files.R index b174e0d..e76183b 100644 --- a/R/read_azure_files.R +++ b/R/read_azure_files.R @@ -53,7 +53,7 @@ read_azure_json <- function(container, file, path = "/", info = NULL, ...) { #' #' @inheritParams read_azure_parquet #' @param ... optional arguments to be passed through to -#' [yyjsonr::read_json_file] +#' [yyjsonr::read_json_file] #' @returns A list #' @export read_azure_jsongz <- function(container, file, path = "/", info = NULL, ...) { @@ -70,11 +70,20 @@ read_azure_jsongz <- function(container, file, path = "/", info = NULL, ...) { #' Read an rds file from Azure storage #' #' @inheritParams read_azure_parquet -#' @returns Data object that was stored in the rds file +#' @param ... optional arguments to be passed through to +#' [AzureStor::storage_load_rds]. For example, a compression type (one of +#' c("unknown", "gzip", "bzip2", "xz", "zstd", "none")) can be provided using +#' the argument `type`, which will be passed on to [memDecompress] via +#' [AzureStor::storage_load_rds]. +# If nothing is provided here, the compression type will be set to "none". +#' @returns The data object that was stored in the rds file #' @export -read_azure_rds <- function(container, file, path = "/", info = NULL) { - check_blob_exists(container, file, "rds", info, path) |> - AzureStor::storage_load_rds(container, file = _) +read_azure_rds <- function(container, file, path = "/", info = NULL, ...) { + # If the user doesn't specify a (de)compression type with `type` in `...`, we + # will set a `type` of "none", as this seems to be the standard on SU Azure + dots <- rlang::dots_list(..., type = "none", .homonyms = "first") + blob <- check_blob_exists(container, file, "rds", info, path) + rlang::inject(AzureStor::storage_load_rds(container, blob, !!!dots)) } diff --git a/man/read_azure_rds.Rd b/man/read_azure_rds.Rd index c099418..8f3e0e4 100644 --- a/man/read_azure_rds.Rd +++ b/man/read_azure_rds.Rd @@ -4,7 +4,7 @@ \alias{read_azure_rds} \title{Read an rds file from Azure storage} \usage{ -read_azure_rds(container, file, path = "/", info = NULL) +read_azure_rds(container, file, path = "/", info = NULL, ...) } \arguments{ \item{container}{An Azure container object, as returned by \link{get_container}} @@ -25,9 +25,15 @@ being read. Useful for checking the function is doing what is expected, but can be turned off with \code{FALSE}. Can be set persistently with the option "azkit.info". If \code{NULL} then it will default to the value of \link[rlang:is_interactive]{rlang::is_interactive} (that is, \code{TRUE} for interactive sessions).} + +\item{...}{optional arguments to be passed through to +\link[AzureStor:storage_save]{AzureStor::storage_load_rds}. For example, a compression type (one of +c("unknown", "gzip", "bzip2", "xz", "zstd", "none")) can be provided using +the argument \code{type}, which will be passed on to \link{memDecompress} via +\link[AzureStor:storage_save]{AzureStor::storage_load_rds}.} } \value{ -Data object that was stored in the rds file +The data object that was stored in the rds file } \description{ Read an rds file from Azure storage