Hi Anshuman, welcome to the community!
The method you suggested above is indeed a good one, but it doesn't really rename the file. It creates another copy of the file with a name of your choice. See below:
# creating dummy data
openxlsx::write.xlsx(x = iris,
file = "try_iris 01012019.xlsx")
#> Note: zip::zip() is deprecated, please use zip::zipr() instead
# name of files in working directory before
list.files()
#> [1] "reprex_reprex.R" "reprex_reprex.spin.R"
#> [3] "reprex_reprex.spin.Rmd" "try_iris 01012019.xlsx"
# what you (@anshuman_k) suggested
openxlsx::saveWorkbook(wb = openxlsx::loadWorkbook(file = "try_iris 01012019.xlsx"),
file = paste0(gsub(pattern = "\\d|.xlsx",
replacement = "",
x = "try_iris 01012019.xlsx"),
format(x = Sys.Date(),
format = "%d%m%Y"),
".xlsx"))
# name of files in working directory after
list.files()
#> [1] "reprex_reprex.R" "reprex_reprex.spin.R"
#> [3] "reprex_reprex.spin.Rmd" "try_iris 01012019.xlsx"
#> [5] "try_iris 01042019.xlsx"
Created on 2019-04-01 by the reprex package (v0.2.1)