Quick wrapper around stringr::str_glue
and here::here
to fill a small recurring need: filling in file paths based on some parameter, but building them relative to the project root.
Usage
glue_here(x, ..., .snake = TRUE, .envir = environment())
Arguments
- x
Character vector of paths, relative to the project root, with glue-style encodings.
- ...
Additional named arguments to fill into glue brackets
- .snake
Boolean, whether text should also be converted to snakecase. Default: TRUE
- .envir
Environment to be passed down
stringr::str_glue
. Probably don't need to worry about it.
Examples
glue_here("{year}_headings_{topic}.txt", year = 2025, topic = "education")
#> [1] "/tmp/RtmppBoLkc/file1e9f3a8215d7/2025_headings_education.txt"
# in a regular script you shouldn't need to worry about setting .envir
# but scoping is weird for package examples
# year <- 2025
# loc <- "New Haven"
env <- rlang::env(year = 2025, loc = "New Haven")
glue_here(c(
"input_data/demo/{loc}_table_{year}.csv",
"{year}_headings.txt"
), .envir = env)
#> [1] "/tmp/RtmppBoLkc/file1e9f3a8215d7/input_data/demo/new_haven_table_2025.csv"
#> [2] "/tmp/RtmppBoLkc/file1e9f3a8215d7/2025_headings.txt"