Skip to content

Instantly share code, notes, and snippets.

@megadix
Last active June 24, 2019 10:11
Show Gist options
  • Select an option

  • Save megadix/8b70889db6294af71119c8cae0b2e9e5 to your computer and use it in GitHub Desktop.

Select an option

Save megadix/8b70889db6294af71119c8cae0b2e9e5 to your computer and use it in GitHub Desktop.
R: read a CSV as a key-value configuration file into a list
key value
rootPath /users/dimitri/data
year 2018
month 2
label a nice label
filename <- "environment.csv"
environment <- read.csv(filename)
configuration <- vector(mode = "list", length = nrow(environment))
names(configuration) <- environment$key
for (i in seq(1, nrow(environment))) {
configuration[[as.character(environment$key[i])]] <- as.character(environment$value[i])
}
print(configuration$rootPath)
print(configuration$year)
print(configuration$month)
print(configuration$label)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment