Skip to content

Instantly share code, notes, and snippets.

@drewlanenga
Created February 1, 2016 06:24
Show Gist options
  • Save drewlanenga/22965c57f560ff85c589 to your computer and use it in GitHub Desktop.
Save drewlanenga/22965c57f560ff85c589 to your computer and use it in GitHub Desktop.
bash in R
set_var <- function(k, v) {
.Internal(Sys.setenv(k, v))
}
# currently just imports env vars
load_bash <- function(bash_file) {
rl <- readLines(bash_file)
# just find statements that begin with `export`
raw.exports <- grep("^export", rl)
exports <- gsub("\"", "", gsub("^export ", "", rl[raw.exports]))
for(export in str_split(exports, "=")) {
# since we're splitting on `=`, some base64 variables will get splat too much
value <- paste0(export[2], rep("=", length(export)-2), collapse = "")
set_var(export[1], value)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment