add_version: Add timestamp and sha string to a file name

View source: R/utils.R

add_versionR Documentation

Add timestamp and sha string to a file name

Description

An alternative to version data is to name it using the sha (unique identifier) of the code using to generate or process the data and the time at which the data was generated or processed. This function adds this information, a version identifier, to a file name (character string)

Usage

add_version(filename, extension = "", sha_nchar = 7, sep = "__")

Arguments

filename

Path sans extension of the file to version

extension

Extension of the file

sha_nchar

Number of characters from the SHA to use as the version identifier

sep

Characters separating the version identifier from the file name

Details

The SHA information is retrieved using git2r::sha. If the code is not running in a context aware of a git repository (for example when code is running inside a container) then this function attempts to get the sha from the environment variable GITHUB_SHA. If both of these methods fail, no sha versioning is added.

Value

A character string with the file name and the version identifier

Examples

if (git2r::in_repository()) {
  add_version("my_file", "csv")
}

WorldFishCenter/peskas.timor.data.pipeline documentation built on April 14, 2025, 1:47 p.m.