This is trivial function wraps paste call and produces a string with Sys.time and an optional extension.

create_dated_file_name(
  x,
  timestamp_format = "%d-%m-%Y",
  sep = "-",
  extension
)

Arguments

x

A character vector.

timestamp_format

A string scalar for time format, as in strptime.

sep

A string scalar to separate file name parts.

extension

A string scalar with file type extension.

Value

A character vector of length corresponding to x.

Details

This simple function is convenient for automatically generating file names with the current date and/or time.

Examples

create_dated_file_name(x = "file_name")
#> [1] "file_name-08-03-2021"
create_dated_file_name(x = "annual_file", timestamp_format = "%Y")
#> [1] "annual_file-2021"
create_dated_file_name(x = "time_file", timestamp_format = "%H:%M:%S")
#> [1] "time_file-19:39:50"