Home > Net >  R rename excel sheet using variable
R rename excel sheet using variable

Time:09-21

I am using write.xlsx and trying to rename an excel sheet to include the current date like bellow:

write.xlsx(dt, file = "C:\\Users\\Docs\\sheet",format(Sys.Date(),"%d_%m_%y"),".xlsx",row.names=FALSE,sheetName = "DATA")

I get the error

Error in if (col.names) iOffset <- 1 : 
  argument is not interpretable as logical

I need the file to be sheet20_09_2021.xlsx. It works using write.csv2 but not using write.xlsx

What is the correct approach ?

Thanks

CodePudding user response:

I think that you forgot to paste your filename first.

ofile <- paste0("C:\\Users\\Docs\\sheet",format(Sys.Date(),"%d_%m_%y"),".xlsx")

ofile
#> [1] "C:\\Users\\Docs\\sheet20_09_21.xlsx"

write.xlsx(dt, file = ofile,row.names=FALSE,sheetName = "DATA")

  •  Tags:  
  • r
  • Related