See Wiki DIY File Restoration

file_snapshots gets the available paths to snapshots of a file on a given snapshot date, month, or year.

diff_snapshot produces a diff of a file and a single snapshot. If RStudio is available, the diff is rendered in the Viewer. Otherwise, a Unix diff is printed to the console.

restore_snapshot restores a file using a single snapshot. By default, this function restores a file to its most recent snapshot, saves the current version in tempdir(), and outputs the result of diff_snapshot. Directories cannot be restored.

file_snapshots(path = NULL, date = Sys.Date(), time = NULL)

diff_snapshot(path = NULL, date = Sys.Date(), time = "last")

restore_snapshot(
  path = NULL,
  date = Sys.Date(),
  time = "last",
  args = c("-p", "-r"),
  new_path = NULL,
  diff = TRUE
)

Arguments

path

a file name or path. Defaults to the path of the source editor context.

date

a character in YYYY-MM-DD format or Date specifying the date range to subset to. Complete dates are not required; character representations of years or months are accepted. Defaults to the current date.

time

character assumed to be in 24-hour format; will be adjusted if "AM" or "PM" is included. If a time is provided, the closest matching snapshot time is selected. "first" and "last" are also accepted. When more than a single date is provided, time should be either NULL, "first", or "last".

args

character vector of additional arguments to cp. The default includes "-p", to preserve mode, ownership, and timestamps; and "-r" to copy directories recursively. See file_copy(args = "help") for cp arguments.

new_path

an optional file name or path indicating where to save the restored snapshot. If provided, the original path will not be modified.

diff

logical indicating whether to call diff_snapshot

Value

file_snapshots – a character vector of file snapshots for a given date. If time is provided, no more than one file snapshot will be returned.

diff_snapshot – invisibly returns NULL

restore_snapshot – a logical indicating whether the copy command was successful

Examples

if (FALSE) { # \dontrun{
file_snapshots(path = "script.R", date = Sys.date())
file_snapshots(date = "2020-01-01")

# check the differences between the latest snapshot and the current
# version of the current source document
diff_snapshot()

# restore the current source document to the most recent snapshot
restore_snapshot()

# restore a file to a snapshot on a given date, closest to a given time
restore_snapshot("file.R", date = "2020-02-19", time = "10:30")

# copy a restored file to a different directory or file
restore_snapshot("file.R", new_path = "archive/")
} # }