Create a Table of the Parameters for Saved Results from RDS Files
Source:R/create_hash_table.R
create_hash_table.Rd
Reads in all the parameter files for a give folder, flattens nested lists, and then combines the parameters into a data frame. Each row in the resulting data frame represents the arguments used for one RDS file, identified by its hash. Optionally, the function can filter the data frame based on specified criteria and save it to a file.
Arguments
- folder
A string specifying the directory containing the RDS files.
- save_path
An optional string specifying the path to save the resulting hash table as a CSV file. If
NULL
, the hash table is not saved.- filter_list
An optional list of filters to apply to the hash table. Each element of the list should be named according to a column in the hash table and contain the value to filter for in that column.
Value
A data frame where each row corresponds to an parameters_list
from an RDS file,
with an additional column for the hash of each set of arguments.
Details
Saving the hash table can be helpful for the manipulation of parameters (see ?update_hash_table
)
or for removal of unwanted results (see ?cleanup_from_hash_table
).
Examples
## Setup
tmp_dir <- file.path(tempdir(), "example")
dir.create(tmp_dir)
## Save objects
obj1 <- rnorm(1000)
obj2 <- data.frame(
x = runif(100),
y = "something",
z = rep(c(TRUE, FALSE), 50)
)
obj3 <- list(obj1, obj2)
params1 <- list(
distribution = "normal",
other_params = list(param1 = TRUE, param2 = 1, param3 = NA)
)
params2 <- list(
distribution = "uniform",
other_params = list(param1 = FALSE, param2 = 2, param3 = "1", param4 = 4)
)
params3 <- list(
distribution = "composite",
other_params = list(param1 = TRUE, param2 = 3, param3 = 1)
)
save_objects(tmp_dir, obj1, params1)
save_objects(tmp_dir, obj2, params2)
save_objects(tmp_dir, obj3, params3)
## Create hash table (and save it)
create_hash_table(tmp_dir, save_path = file.path(tmp_dir, "hash_table.csv"))
#> distribution other_params[[param1]] other_params[[param2]]
#> 1 uniform FALSE 2
#> 2 composite TRUE 3
#> 3 normal TRUE 1
#> other_params[[param3]] other_params[[param4]]
#> 1 1 4
#> 2 1 <NA>
#> 3 <NA> <NA>
#> script_name hash
#> 1 4aaef0ca-7936-4076-b370-27ac49c18337 181c74ea91113c0c
#> 2 4aaef0ca-7936-4076-b370-27ac49c18337 3a21c1fc17d5f68a
#> 3 4aaef0ca-7936-4076-b370-27ac49c18337 5964241557faff5a
## Cleanup
unlink(tmp_dir, recursive = TRUE)