Assume we are exloring some data set, and during our work, we’ve created a number of files with their specific structure.

Then, we have two possible ways to represent this structure using path.chain package.

1. Using full_path_chain function, which returns a list of nested directories.

Configurtion file config.yaml will look as follows:

We can customize keys naming convention using naming argument.

If dir structure is not a only element in ou config file, we can wrap it with some additional list.

list(kDirs = full.path.chain.2) %>% 
  list(default = .) %>% 
  yaml::write_yaml(temp_path("config.yaml"))

Then, we can load such config file using {config} package:

What if we want to keep absolute paths rather than the relative ones?

full_path_chain(normalizePath(temp_path("files")), "kRoot", naming_fun) %>% 
  as_config("default", "kDirs") %>% 
  yaml::write_yaml(temp_path("config.yaml"))

Wrapping with default key is required by config package.

2. Using path_chain function, which returns nested path_chain objects.

path.chain <- path_chain(temp_path("files"), naming = naming_fun)

class(path.chain)
#> [1] "path_chain"

print(path.chain$kData$kExample1)
#> [1] "files/data/example1.RData"

# Most verbose version
path.chain %>% 
  as.list(root.name = "kRoot") %>%
  as_config("default", "kDirs") %>% 
  yaml::write_yaml(temp_path("config.yaml"))

# Conciser
path.chain %>% 
  as_config("default", "kDirs", root.name = "kRoot") %>% 
  yaml::write_yaml(temp_path("config.yaml"))

As you can see, such structur of the config file seems to be more legible than the one produced with full_path_chain function. The config file shown above can be easily consumed using config package and as_path_chain function.