-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to write glue()
wrappers
#281
Comments
Write a wrapper function that does what you want? |
I did try that but unfortunately it doesn't work, at least not trivially, because of the environments in which it's called. |
For example: myglue <- function(...) {
glue::glue(..., .open = "{{", .close = "}}")
}
# this works
x <- 5
message(myglue("x: {{x}}"))
fxn <- function() {
y <- 7
# this doesn't work
message(myglue("y: {{y}}"))
}
fxn() |
You need to wire up myglue <- function(..., .envir = parent.frame()) {
glue::glue(..., .open = "{{", .close = "}}", .envir = .envir)
}
# this works
x <- 5
message(myglue("x: {{x}}"))
#> x: 5
fxn <- function() {
y <- 7
# this also works
message(myglue("y: {{y}}"))
}
fxn()
#> y: 7 Created on 2022-12-22 with reprex v2.0.2.9000 |
@jennybc I feel like an example of this pattern would be useful in the docs |
.trim
or .open
glue()
wrappers
And improve the documentation for the |
I'm developing a package that uses a lot of glue. In each usage I want to use
.trim = FALSE
. It's very troublesome to add.trim = FALSE
parameter to every glue call.It would be wonderful to be able to set a global option for that, or for any other parameters (I also use
.open = "{{"
in every call).The text was updated successfully, but these errors were encountered: