Learn R Programming

reproducible (version 1.1.1)

Checksums: Calculate checksum

Description

Verify (and optionally write) checksums. Checksums are computed using .digest, which is simply a wrapper around digest::digest.

Usage

Checksums(
  path,
  write,
  quickCheck = FALSE,
  checksumFile = file.path(path, "CHECKSUMS.txt"),
  files = NULL,
  ...
)

# S4 method for character,logical Checksums( path, write, quickCheck = FALSE, checksumFile = file.path(path, "CHECKSUMS.txt"), files = NULL, ... )

# S4 method for character,missing Checksums( path, write, quickCheck = FALSE, checksumFile = file.path(path, "CHECKSUMS.txt"), files = NULL, ... )

Arguments

path

Character string giving the directory path containing CHECKSUMS.txt file, or where it will be written if checksumFile = TRUE.

write

Logical indicating whether to overwrite CHECKSUMS.txt. Default is FALSE, as users should not change this file. Module developers should write this file prior to distributing their module code, and update accordingly when the data change.

quickCheck

Logical. If TRUE, then this will only use file sizes, rather than a digest::digest hash. This is generally faster, but will be much less robust.

checksumFile

The filename of the checksums file to read or write to. The default is CHECKSUMS.txt located at file.path(path, module, "data", checksumFile). It is likely not a good idea to change this, and should only be used in cases such as Cache, which can evaluate if the checksumFile has changed.

files

An optional character string or vector of specific files to checksum. This may be very important if there are many files listed in a CHECKSUMS.txt file, but only a few are to be checksummed.

...

Passed to digest and write.table. For digest, the notable argument is algo. For write.table, the notable argument is append.

Value

A data.table with columns: result, expectedFile, actualFile, checksum.x, checksum.y, algorithm.x, algorithm.y, filesize.x, filesize.y indicating the result of comparison between local file (x) and expectation based on the CHECKSUMS.txt file.

Examples

Run this code
# NOT RUN {
moduleName <- "my_module"
modulePath <- file.path("path", "to", "modules")

## verify checksums of all data files
Checksums(moduleName, modulePath)

## write new CHECKSUMS.txt file

# 1. verify that all data files are present (and no extra files are present)
list.files(file.path(modulePath, moduleName, "data"))

# 2. calculate file checksums and write to file (this will overwrite CHECKSUMS.txt)
Checksums(moduleName, modulePath, write = TRUE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab