name_env_out | R Documentation |
Either create directory path for saving outputs or parse the meta data from an output directory path. The first elements in the list will form directories. The second elements in the list form the name of each directory, separated by "__".
name_env_out(
set_list,
base_dir = NULL,
show_null = FALSE,
return_contexts = TRUE,
dir_with_context = FALSE,
all_files = FALSE,
search_dir = if (is.null(base_dir)) here::here() else NULL,
reg_exp = NULL,
...
)
set_list |
Nested list, with two levels, of critical settings (only) for use in output path names. The first elements of the list will return directories. Elements within each of the first elements of the list are concatenated to form the name of each directory (see examples). |
base_dir |
Character. Directory prefix to the output path. |
show_null |
Logical. Display "NULL" or "NA" in names (or gsub it out with ""). |
return_contexts |
Logical. If TRUE (default) contexts, directories and path are returned, otherwise just directories and path. |
dir_with_context |
Logical. If FALSE (default) the first elements in
|
all_files |
Logical or numeric. Return files within the |
search_dir |
Character. Path(s) to search for the |
reg_exp |
Character. Combined with |
... |
Passed to |
Tibble containing:
all contexts: named as per the second level elements of set_list
directories: a directory for each element in the first level of set_list
path: the output path, prepended with base_dir
# a list of settings
settings <- list(extent = list(polygons = "sa_ibrasub_xn"
, filt_col = NULL
, filt_level = NULL
, buffer = 0
, temp_ext = "P50Y"
)
, grain = list(x = 90
, y = 90
, z = "P50Y"
, taxonomic = "species"
)
, reliability = list(rel_geo = 10000
, rel_temp = "P10Y"
)
, aoi = list(polygons = "lsa"
, filt_col = "LSA"
, filt_level = "GA"
, buffer = 0
)
)
# generate an 'out directory' based on those settings
settings$out_dir <- name_env_out(set_list = settings#[1:4]
, base_dir = here::here("inst", "examples")
, dir_with_context = TRUE
)$path
settings$out_dir
# create the 'out directory'
fs::dir_create(settings$out_dir)
# put some junk files in the 'out directory'
purrr::map(1:10
, \(x) tempfile(tmpdir = settings$out_dir)
) %>%
fs::file_create()
# use name_env_out to return the list of files, based on the settings
files <- name_env_out(set_list = settings[1:4]
, base_dir = here::here("inst", "examples")
, dir_with_context = TRUE
, all_files = TRUE
# dots
, recurse = TRUE
) %>%
tidyr::unnest(cols = c(files)
, keep_empty = TRUE
)
files
# clean up
# fs::dir_delete(settings$out_dir) # only run this if you're sure it is safe
rm(settings, files)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.