rehash: Rehash RDS Files in a Directory

View source: R/rehash.R

rehashR Documentation

Rehash RDS Files in a Directory

Description

This function processes all RDS files in a specified directory, generating new hashes for each file's args_list and renaming the files accordingly. It's useful when changing the hash generation algorithm or parameters (if the parameters are manually changed for some reason).

Usage

rehash(
  folder,
  hash_includes_timestamp = FALSE,
  ignore_na = TRUE,
  alphabetical_order = TRUE,
  algo = "xxhash64"
)

Arguments

folder

A string specifying the directory containing the RDS files to be rehashed.

hash_includes_timestamp

Logical; if TRUE, includes timestamps in the hash generation.

ignore_na

Logical; if TRUE, NA values are ignored during hash generation.

alphabetical_order

Logical; if TRUE, parameters are sorted alphabetically before hash generation.

algo

The (potentially new) hash algorithm to use (see ?digest)

Value

The function does not return a value but renames the RDS files in the specified directory based on new hashes.

Examples

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

# Save example 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)

## See current file names
list.files(tmp_dir)

## Rehash with new algo
rehash(tmp_dir, algo = "xxhash32")

## Observe new file names
list.files(tmp_dir)

## Cleanup
unlink(tmp_dir, recursive = TRUE)

indexr documentation built on April 12, 2025, 1:32 a.m.