Skip to contents

Tagging is mainly helpful for removing unused results. start_tagging() initializes the tagging process by creating a txt file in the results directory which will keep a record of which results are being read by read_objects(). cleanup() removes any .rds files in the specified folder that are not listed in the tagging file. close_tagging() deletes the tagging file, ending the tagging session.

Usage

start_tagging(folder, tagging_file_name = "indexr_tagging.txt")

cleanup(
  folder,
  tagging_file_name = "indexr_tagging.txt",
  cutoff_date = NULL,
  request_confirmation = TRUE
)

close_tagging(folder, tagging_file_name = "indexr_tagging.txt")

Arguments

folder

A character string specifying the path to the directory where the result files are saved and where the tagging file will be created.

tagging_file_name

A character string for a txt file the tagging information is to be saved under.

cutoff_date

A character string in "%Y-%m-%d %H:%M:%S" format used to specify that any tagged files before the date should also be removed.

request_confirmation

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

Value

No return value. This function is called for its side effects.

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 have been saved
list.files(tmp_dir)
#> [1] "b7d0393187daaf38.rds"            "b7d0393187daaf38_parameters.rds"
#> [3] "fc9189e50b6d4b04.rds"            "fc9189e50b6d4b04_parameters.rds"

## Start tagging
start_tagging(tmp_dir)
#> [1] TRUE

## Read back in one the first file, this causes this file to be tagged
res1 <- read_objects(folder = tmp_dir, parameters_list = parameters_list1)
#> Warning: File not found for hash: 37e8f5a7fdadf899

## Remove untagged file without confirmation (that for parameters_list2)
cleanup(tmp_dir, request_confirmation = FALSE)
#> Error in cleanup(tmp_dir, request_confirmation = FALSE): The tagging file 'indexer_tagging.txt' is empty. No tagged files to compare for cleanup.

## See that one file was removed
list.files(tmp_dir)
#> [1] "b7d0393187daaf38.rds"            "b7d0393187daaf38_parameters.rds"
#> [3] "fc9189e50b6d4b04.rds"            "fc9189e50b6d4b04_parameters.rds"
#> [5] "indexr_tagging.txt"             

## Close tagging (just removes tagging file)
close_tagging(tmp_dir)
#> Tagging file 'indexr_tagging.txt' has been deleted.

## Cleanup
unlink(tmp_dir, recursive = TRUE)