Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206235

Self-referential values in an R config file

$
0
0

Using the config package, I'd like elements to reference other elements, like how path_file_a references path_directory.

config.yml file in the working directory:

default:
  path_directory  : "data-public"
  path_file_a     : "{path_directory}/a.csv"
  path_file_b     : "{path_directory}/b.csv"
  path_file_c     : "{path_directory}/c.csv"
  # recursive     : !expr file.path(config::get("path_directory"), "c.csv")

Code:

config <- config::get()

config$path_file_a
# Returns:  "{path_directory}/a.csv"

glue::glue(config$path_file_a, .envir = config)
# Returns: "data-public/a.csv"

I can use something like glue::glue() on the value returned by config$path_file_a.
But I'd prefer to have the value already substituted so config$path_file_a contains the actual value (not the template for the value).

As you might expect, uncommenting the recursive line creates an endless self-referential loop.

Are there better alternatives to glue::glue(config$path_file_a, .envir = config)?


Viewing all articles
Browse latest Browse all 206235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>