Search code examples
rnaming-conventionsnamingr-xlsx

Remove space from exported filename in R using xlsx package


Trying to export a file using write.xlsx() from package "xlsx".

File export works as expected, however having trouble with the naming convention.

I wish for the file to be names as follows:

filename <today's date>.xlsx 

At present I can do either of the following:

write.xlsx(exports, paste("filename", Sys.Date(),".xlsx"))

which gives:

filename 2020-04-21 .xlsx

Or I can write

write.xlsx(exports, paste("filename", Sys.Date(),".xlsx", sep = ""))

which gives:

filename2020-04-21.xlsx

How do I remove the space between the date and file extension such that the file name is:

filename 2020-04-01.xlsx

I appreciate this is somewhat a vanity thing and I could use sep = "_" to place underscores throughout, but this is not the naming convention I am trying to achieve.


Solution

  • Wow. I cannot believe I didn't think to just add an additional space in the last example.

    Going to blame cabin fever from social distancing/isolating for that little derp.

    write.xlsx(exports, paste("filename ", Sys.Date(),".xlsx", sep = ""))