append_time: Append a timestamp to a filepath

View source: R/filepaths.R

append_timeR Documentation

Append a timestamp to a filepath

Description

Given a filepath this function will append a timestamp to the filename. By default the timestamp will be formatted as %Y_%m_%d_%H%M.

Usage

append_time(path, time = Sys.time(), format = "%Y_%m_%d_%H%M")

Arguments

path

(character) the path to the file as if it didn't have an appended timestamp

time

(datetime, default = Sys.time()) the datetime that will be appended to path.

format

a character string. The default for the format methods is "%Y-%m-%d %H:%M:%S" if any element has a time component which is not midnight, and "%Y-%m-%d" otherwise. If options("digits.secs") is set, up to the specified number of digits will be printed for seconds.

Value

a filepath

Examples

## Not run: 
path <- append_time(
  path = "/data/raw.xlsx",
  time = ymd_hm("2021-05-20 14:30")
)

# Returns:
# "/data/raw_2021_05_20_1430.xlsx"

## End(Not run)

baslat/sak documentation built on April 14, 2025, 4:14 p.m.