Before rerunning a step that overwrites files of the data folder, copy
them to a dated folder backup_before_<reason>_<date>/;
after the run, compare the files with their backup to see what changed.
Arguments
- files
Character. Paths of the files to back up (existing files).
- reason
Character. Why the files are about to change (becomes part of the folder name, e.g.
"cleaning_v4").- backup_dir
Character. Folder in which the backup folder is created.
- date
A date used in the folder name.
- backup
A manifest returned by
backup_files(), or the path of a backup folder (which holdsmanifest.csv).
Value
backup_files(): a manifest (data.table with file, backup,
bytes, md5), also saved as manifest.csv in the backup folder,
invisibly. compare_with_backup(): a data.table with file and
status ("unchanged", "changed", "missing").
Details
If the backup folder already exists (two backups the same day for the same reason), the time is added to its name: a backup never overwrites another one.
See also
Other files:
dated_file_name(),
free_disk_gb(),
write_gz_text()
Examples
dir <- file.path(tempdir(), "backup_example")
dir.create(dir, showWarnings = FALSE)
f <- file.path(dir, "matches.csv")
writeLines("a,b", f)
backup <- backup_files(f, reason = "matching_v2", backup_dir = dir)
#> ✔ 1 file backed up to /tmp/RtmpKqItGK/backup_example/backup_before_matching_v2_2026-11-08.
writeLines("a,c", f)
compare_with_backup(backup)
#> ℹ 0 unchanged, 1 changed, 0 missing.
#> file status
#> <char> <char>
#> 1: /tmp/RtmpKqItGK/backup_example/matches.csv changed