Skip to content

Instantly share code, notes, and snippets.

@evanlinde
Created December 23, 2015 14:45
Show Gist options
  • Save evanlinde/3a1b3e108a55f7e71dd0 to your computer and use it in GitHub Desktop.
Save evanlinde/3a1b3e108a55f7e71dd0 to your computer and use it in GitHub Desktop.
R function to read variable definition from a bash script
readSetting <- function(setting_name, file){
# Settings appear in the file in the form of
# SETTING_NAME="SETTING_VALUE"
# with no leading whitespace characters.
setting_begin <- paste0("^", setting_name, "=\"")
setting_end <- "\" *$"
setting_line <- grep(setting_begin, readLines(file), value=TRUE)
setting_value <- gsub(setting_end, "", gsub(setting_begin, "", setting_line, fixed=FALSE), fixed=FALSE)
return(setting_value)
}
settings_file <- "hpc_experiment_conf"
FUDGE_WORK_DIR <- readSetting("FUDGE_WORK_DIR",settings_file)
FUDGE_DATA_DIR <- readSetting("FUDGE_DATA_DIR",settings_file)
WALLTIME_COMBINE <- readSetting("WALLTIME_COMBINE",settings_file)
QUEUE_COMBINE <- readSetting("QUEUE_COMBINE",settings_file)
EMAIL_NOTIFY_COMBINE <- readSetting("EMAIL_NOTIFY_COMBINE",settings_file)
cat("FUDGE_WORK_DIR: ",FUDGE_WORK_DIR,"\n",sep="")
cat("FUDGE_DATA_DIR: ",FUDGE_DATA_DIR,"\n",sep="")
cat("WALLTIME_COMBINE: ",WALLTIME_COMBINE,"\n",sep="")
cat("QUEUE_COMBINE: ",QUEUE_COMBINE,"\n",sep="")
cat("EMAIL_NOTIFY_COMBINE: ",EMAIL_NOTIFY_COMBINE,"\n",sep="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment