Commit 7fa8d09b authored by Holger Brandl's avatar Holger Brandl

added `interp_from_env`

parent 64ef875b
......@@ -584,3 +584,13 @@ add_prefix = function(filename) {
file.path(dirname(filename), prefixName)
}
## https://stackoverflow.com/questions/18669886/how-to-unfold-user-and-environment-variable-in-r-language/46240642#46240642
interp_from_env = function(path){
e <- new.env()
(system("export", intern=T) %>% str_split_fixed(" ", 2))[,2] %>% map(~eval(parse(text=.), envir=e))
glue::glue(path, .envir=e, .open="${")
}
# #usage examples
# read.delim(interp_from_env("${PRJ_DATA}/foo.txt") )
# source(interp_path("${HOME}/bar.R"))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment