Skip to content

Commit

Permalink
Add trim param to str_glue() (#562)
Browse files Browse the repository at this point in the history
Fixes #538
  • Loading branch information
Edgar-Zamora authored Aug 15, 2024
1 parent d681e45 commit 83a72a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion man/str_glue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

})

0 comments on commit 83a72a1

Please sign in to comment.