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] "36eb5e4bab87a60a.rds" "7c81789e9ebbfc58.rds" "indexr.yaml"         
#> [4] "indexr.yaml.lock"    

## 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/Rtmpla9hQE/example/36eb5e4bab87a60a.rds
#> /tmp/Rtmpla9hQE/example/7c81789e9ebbfc58.rds
#> Specified files and YAML entries have been deleted.

## See the files have been deleted
list.files(tmp_dir)
#> [1] "indexr.yaml"      "indexr.yaml.lock"

## Cleanup
unlink(tmp_dir, recursive = TRUE)