Add today's date to the filename
Arguments
- ...
file name or path to concat
- format
time format e.g. %d-%b-%Y , refer to
date3to1
for date formats
Details
The present function enables users to add the current date to the file name, facilitating the straightforward saving of files with their respective dates. It accepts different file paths and names as arguments, as demonstrated in the example section. This functionality simplifies the process of associating a file's creation date with its name, aiding users in recalling when a file was saved. Moreover, it serves as a preventive measure against unintentional overwriting of files created on different dates.
Examples
# Task 1
fAddDate("path1/","path2/filepre","filemid","fileend.png")
#> [1] "path1/path2/fileprefilemidfileend_04-Aug-2024.png"
# Task 2
fAddDate(c("path1/","path2/"),"filepre","filemid","fileend.png")
#> [1] "path1/fileprefilemidfileend_04-Aug-2024.png"
#> [2] "path2/fileprefilemidfileend_04-Aug-2024.png"
# Task 3
fAddDate("one_file_name_fileend.pdf")
#> [1] "one_file_name_fileend_04-Aug-2024.pdf"
# Task 4
fAddDate(c("path1/","path2/"),"file1-","filemid",c("fileend.png",".pdf"))
#> [1] "path1/file1-filemidfileend_04-Aug-2024.png"
#> [2] "path2/file1-filemid_04-Aug-2024.pdf"
# Task 5
data("USArrests")
USArrests$fn = paste0(row.names(USArrests), ".txt")
head(fAddDate(USArrests$fn),10)
#> [1] "Alabama_04-Aug-2024.txt" "Alaska_04-Aug-2024.txt"
#> [3] "Arizona_04-Aug-2024.txt" "Arkansas_04-Aug-2024.txt"
#> [5] "California_04-Aug-2024.txt" "Colorado_04-Aug-2024.txt"
#> [7] "Connecticut_04-Aug-2024.txt" "Delaware_04-Aug-2024.txt"
#> [9] "Florida_04-Aug-2024.txt" "Georgia_04-Aug-2024.txt"
# Task 6: format date - month.day.year
fAddDate("sample_file_name.pdf", format = "%B.%d.%YYYY")
#> [1] "sample_file_name_August.04.2024YYY.pdf"
# Task 7: format date - year_month
fAddDate("sample_file_name.pdf", format = "%YYYY_%m")
#> [1] "sample_file_name_2024YYY_08.pdf"