Revise a header that is already in a file, changing only the fields you name.
Each update is either a replacement value or a function that receives the
current value of the field and returns the new one. year_extend() and
author_add() build the two most useful such functions, and stamp_edits()
bundles a set of them for reuse. For the common tasks there are also dedicated
verbs, stamp_bump_year() and stamp_add_author().
Arguments
- file
Character. Path to a file or directory to update.
- ...
Named updates to apply to header fields (each value is a new value or a function of the field's current value), or a single
stamp_edits()bundle.- action
Character. Action to perform: "modify", "dryrun", or "backup".
- recursive
Logical. When
fileis a directory, descend into subdirectories.- pattern
Character or NULL. When
fileis a directory, only update files whose name matches this pattern.
Value
TRUE invisibly on success (a stamp_update_preview for
action = "dryrun"), or a stamp_dir_results object when file is a
directory.
Details
If file is a directory, every already-stamped file it contains is updated
and a stamp_dir_results object is returned.
Examples
file <- tempfile(fileext = ".R")
writeLines(c("# Copyright (c) 2020", "# Author: Jane", "", "x <- 1"), file)
stamp_update(file, copyright = year_extend(), author = author_add("Sam"))
readLines(file)[1:2]
#> [1] "# Copyright (c) 2020-2026" "# Author: Jane and Sam"