indexr
is an R package designed to automate the saving
and reading of R objects resulting from simulations based on their
parameter configurations. It provides tools for saving, reading,
updating, and managing objects with hashed file names, enabling
efficient and organized data handling. This package is especially useful
for scenarios involving extensive parameter tuning, simulations, or any
context where managing a large number of R objects is required.
indexr
takes an opinionated perspective on how
simulations should be set up and as such enforces certain behaviors,
which will be explained more in a coming vignette.
save_objects
) and read (read_objects
) R
objects with file names generated from parameter hashes, avoiding
cumbersome or uninformative file names.create_hash_table
) from your RDS files for easy reference
of what simulations you have in a given folder.start_tagging
and easily remove unused results with
cleanup
. Or remove specific simulations with the
combination of create_hash_table
and
cleanup_from_hash_table
.update_hash_table
.check_hash_existence
to avoid rerunning simulations you may
have forgot about.Install indexr
from GitHub (future CRAN release
planned):
# install.packages("devtools")
::install_github("lharris421/indexr") devtools
Here’s a quick start guide to using indexr
. Running this
code will save and delete two files to R sessions temp directory.
library(indexr)
# Example usage of save_objects
<- list(
parameters_list iterations = 1000,
x_dist = "rnorm",
x_dist_options = list(n = 10, mean = 1, sd = 2),
error_dist = "rnorm",
error_dist_options = list(n = 10, mean = 0, sd = 1),
beta0 = 1,
beta1 = 1
)
<- numeric(parameters_list$iterations)
betas for (i in 1:parameters_list$iterations) {
<- do.call(parameters_list$x_dist, parameters_list$x_dist_options)
x <- do.call(parameters_list$error_dist, parameters_list$error_dist_options)
err <- parameters_list$beta0 + parameters_list$beta1*x + err
y <- coef(lm(y ~ x))["x"]
betas[i]
}
<- file.path(tempdir(), "example")
tmp_dir dir.create(tmp_dir)
save_objects(folder = tmp_dir, results = betas, parameters_list = parameters_list)
# Example usage of read_objects (consider clearing environment before running)
<- list(
parameters_list iterations = 1000,
x_dist = "rnorm",
x_dist_options = list(n = 10, mean = 1, sd = 2),
error_dist = "rnorm",
error_dist_options = list(n = 10, mean = 0, sd = 1),
beta0 = 1,
beta1 = 1
)
<- file.path(tempdir(), "example")
tmp_dir <- read_objects(folder = tmp_dir, parameters_list = parameters_list)
betas hist(betas)
# Create a hash table
<- create_hash_table(folder = tmp_dir)
hash_table
# Delete files based on hash table
cleanup_from_hash_table(folder = tmp_dir, hash_table = hash_table, mode = "all")
# Remove the tmp folder
unlink(tmp_dir, recursive = TRUE)
For detailed usage, please refer to the package documentation.
Contributions to indexr
are welcome! Whether it’s
feature requests, bug reports, or code contributions, your input is
highly valued. Please feel free to submit issues and pull requests on
the GitHub repository.