This function always treats first object in the nested list as a subdirectory root path
as_path_chain(nested.list, root.name = "kRoot")
nested.list | `list` object with nested lists/strings inside |
---|---|
root.name | key for root directory |
path_chain object
library(magrittr) # Manually created nested list nested.list <- list(kRoot = "root", "file1.txt", list("subdir", "file2.csv")) chainable.path <- as_path_chain(nested.list) class(chainable.path)#> [1] "path_chain"chainable.path$.#> [1] "root/"chainable.path$subdir$files2.csv#> NULL# Nested list from config file tmp <- create_temp_dir("files") create_sample_dir(tmp, override = TRUE)#> [1] TRUE#> /tmp/Rtmp4l1UVj/files #> ├── data #> │ ├── example1.RData #> │ ├── example2.RData #> │ └── persons.csv #> └── docs #> └── schema.txtpath_chain(tmp, naming = naming_k) %>% as.list(root.name = "kRoot") %>% as_config("default", "kDirs") %>% yaml::write_yaml(temp_path("config.yaml")) chainable.path <- config::get("kDirs", "defaul", temp_path("config.yaml")) %>% as_path_chain() class(chainable.path)#> [1] "path_chain"chainable.path$.#> [1] "files/"chainable.path$kData$kExample1#> [1] "files/data/example1.RData"