diff --git a/R/glue.R b/R/glue.R index 13744b54..aae88e90 100644 --- a/R/glue.R +++ b/R/glue.R @@ -34,8 +34,8 @@ #' #' # `str_glue_data()` is useful in data pipelines #' mtcars %>% str_glue_data("{rownames(.)} has {hp} hp") -str_glue <- function(..., .sep = "", .envir = parent.frame()) { - glue::glue(..., .sep = .sep, .envir = .envir) +str_glue <- function(..., .sep = "", .envir = parent.frame(), .trim = TRUE) { + glue::glue(..., .sep = .sep, .envir = .envir, .trim = .trim) } #' @export diff --git a/man/str_glue.Rd b/man/str_glue.Rd index 11a8bde1..72d579fd 100644 --- a/man/str_glue.Rd +++ b/man/str_glue.Rd @@ -5,7 +5,7 @@ \alias{str_glue_data} \title{Interpolation with glue} \usage{ -str_glue(..., .sep = "", .envir = parent.frame()) +str_glue(..., .sep = "", .envir = parent.frame(), .trim = TRUE) str_glue_data(.x, ..., .sep = "", .envir = parent.frame(), .na = "NA") } @@ -23,6 +23,9 @@ Named arguments are taken to be temporary variables available for substitution. evaluated from left to right. If \code{.x} is an environment, the expressions are evaluated in that environment and \code{.envir} is ignored. If \code{NULL} is passed, it is equivalent to \code{\link[=emptyenv]{emptyenv()}}.} +\item{.trim}{[\code{logical(1)}: \sQuote{TRUE}]\cr Whether to trim the input +template with \code{\link[glue:trim]{trim()}} or not.} + \item{.x}{[\code{listish}]\cr An environment, list, or data frame used to lookup values.} \item{.na}{[\code{character(1)}: \sQuote{NA}]\cr Value to replace \code{NA} values diff --git a/tests/testthat/test-glue.R b/tests/testthat/test-glue.R index 636da63a..ddc79a26 100644 --- a/tests/testthat/test-glue.R +++ b/tests/testthat/test-glue.R @@ -5,3 +5,9 @@ test_that("verify wrapper is functional", { expect_equal(as.character(str_glue_data(df, "a {b}", b = "b")), "a b") }) +test_that("verify trim is functional", { + expect_equal(as.character(str_glue("L1\t \n \tL2")), "L1\t \nL2") + + expect_equal(as.character(str_glue("L1\t \n \tL2", .trim = FALSE)), "L1\t \n \tL2") + +})