Skip to contents

Test helper to write a test config to file

Usage

local_write_cfg(
  cfg_name = "tmp_cfg.yml",
  dir = fs::file_temp(pattern = "R-dimex-tst-cfg_"),
  envir = parent.frame()
)

Arguments

cfg_name

A character string: name of the config file to write.

dir

A temporary directory as a character string or as would be returned by fs::file_temp().

envir

The environment to use for scoping which must default to parent.frame() - do NOT changed this by supplying an alternative as this is used by withr::defer().

Value

The name of the temporary directory that contains the saved config file as a character string (not as an fs_path object).

Details

A call to local_write_cfg() will write a config to file to a temporary directory and set up a deferred event to delete the directory (and file) when the calling function exits (i.e., within the appropriate scope as controlled by the envir argument).

Examples

if (FALSE) { # \dontrun{
tmp_dir <- local_write_cfg()
} # }