Created
February 1, 2016 06:24
-
-
Save drewlanenga/22965c57f560ff85c589 to your computer and use it in GitHub Desktop.
bash in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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