Last active
June 24, 2019 10:11
-
-
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
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
| key | value | |
|---|---|---|
| rootPath | /users/dimitri/data | |
| year | 2018 | |
| month | 2 | |
| label | a nice label |
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
| 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