Skip to contents

Allows the user to leverage the generate_hash function to generate a table that is subsequently used to remove indicated results.

Usage

cleanup_from_hash_table(
  folder,
  hash_table,
  mode = c("manual", "all"),
  column = NULL,
  request_confirmation = TRUE
)

Arguments

folder

A string specifying the directory containing the RDS files.

hash_table

A data.frame from create_hash_table.

mode

A character string. When mode = "manual" (default) the function expects that the user will add a column to a hash table that indicated which files to delete. When mode = "all", any results in the hash table will be removed.

column

A character string indicating the logical column in hash_table specifying which files to delete.

request_confirmation

Logical, if TRUE will request user input before proceeding to delete files.

Value

Nothing, this function is called for its side effects.

Details

There are a few ways to use this. When mode = "manual" (default) the function expects that the user will add a column to a hash table that indicated which files to delete. When mode = "all", any results in the hash table will be removed. This is generally only used when a filter_list is passed to create_hash_table.

Examples

## Setup
tmp_dir <- file.path(tempdir(), "example")
dir.create(tmp_dir)

## Save example objects
parameters_list1 <- list(example = "tagging1")
parameters_list2 <- list(example = "tagging2")
save_objects(folder = tmp_dir, results = 1, parameters_list = parameters_list1)
save_objects(folder = tmp_dir, results = 2, parameters_list = parameters_list2)

## See the files saved
list.files(tmp_dir)
#> [1] "b7d0393187daaf38.rds"            "b7d0393187daaf38_parameters.rds"
#> [3] "fc9189e50b6d4b04.rds"            "fc9189e50b6d4b04_parameters.rds"

## Create hash table (flat file of result parameters)
hash_table <- create_hash_table(folder = tmp_dir)

## Delete "all" files based on hash table, without confirmation
cleanup_from_hash_table(
  folder = tmp_dir, hash_table = hash_table, mode = "all", request_confirmation = FALSE
)
#> The following .rds files will be removed:
#> /tmp/Rtmp9Prjgj/example/b7d0393187daaf38.rds
#> /tmp/Rtmp9Prjgj/example/fc9189e50b6d4b04.rds
#> /tmp/Rtmp9Prjgj/example/b7d0393187daaf38_parameters.rds
#> /tmp/Rtmp9Prjgj/example/fc9189e50b6d4b04_parameters.rds
#> Specified files have been deleted.

## See the files have been deleted
list.files(tmp_dir)
#> character(0)

## Cleanup
unlink(tmp_dir, recursive = TRUE)