diff --git a/DESCRIPTION b/DESCRIPTION index d27eb9a1..b52bd79d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: gDRutils Type: Package Title: A package with helper functions for processing drug response data -Version: 1.5.1 +Version: 1.5.2 Date: 2024-11-05 Authors@R: c(person("Bartosz", "Czech", role=c("aut"), comment = c(ORCID = "0000-0002-9908-3007")), diff --git a/NAMESPACE b/NAMESPACE index a9f9de03..046e9c27 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,6 +55,7 @@ export(get_default_identifiers) export(get_duplicated_rows) export(get_env_assay_names) export(get_env_identifiers) +export(get_env_var) export(get_expect_one_identifiers) export(get_experiment_groups) export(get_header) diff --git a/NEWS.md b/NEWS.md index 7151b930..cd989f6d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +## gDRutils 1.5.2 - 2024-11-05 +* add `get_env_var` helper + ## gDRutils 1.5.1 - 2024-11-05 * synchronize Bioconductor and GitHub versioning diff --git a/R/duplicates.R b/R/duplicates.R index 95173e8f..f2208995 100644 --- a/R/duplicates.R +++ b/R/duplicates.R @@ -185,3 +185,4 @@ throw_msg_if_duplicates <- function(dt, assay_name = "unknown", msg_f = stop, pr msg_f(paste0(msg, msg2, msg3)) } } + diff --git a/R/utils.R b/R/utils.R index c3fd7861..69ce7b59 100644 --- a/R/utils.R +++ b/R/utils.R @@ -761,3 +761,23 @@ calc_sd <- function(x) { } } + + +#' safe wrapper of Sys.getenv() +#' +#' So far the helper is needed to handle env vars containing `:` +#' for which the backslash is automatically added in some contexts +#' and R could not get the original value for these env vars. +#' +#' @param x string with the name of the environemntal variable +#' @param ... additional params for Sys.getenev +#' @keywords package_utils +#' +#' @examples +#' get_env_var("HOME") +# +#' @export +#' @return sanitized value of the env variable +get_env_var <- function(x, ...) { + gsub("\\\\", "", Sys.getenv(x, ...)) +} diff --git a/man/get_env_var.Rd b/man/get_env_var.Rd new file mode 100644 index 00000000..c9ef9220 --- /dev/null +++ b/man/get_env_var.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{get_env_var} +\alias{get_env_var} +\title{safe wrapper of Sys.getenv()} +\usage{ +get_env_var(x, ...) +} +\arguments{ +\item{x}{string with the name of the environemntal variable} + +\item{...}{additional params for Sys.getenev} +} +\value{ +sanitized value of the env variable +} +\description{ +So far the helper is needed to handle env vars containing \code{:} +for which the backslash is automatically added in some contexts +and R could not get the original value for these env vars. +} +\examples{ +get_env_var("HOME") +} +\keyword{package_utils}