0

I have a data frame which I want to store in an excel file. Additionally, I have a variable with name dateofentry which has a value. I want the excel file which will be saved to have this variable name in it along with word report. I have written the following code, however no file is getting created. Can someone please help in this regard. Thanks

library(openxlsx)

first_col <- c("A","B","C")
second_col <-c("1","2","3")

df<- data.frame(first_col,second_col)

dateofentry <- "02/03/2022"
filename=paste0(dateofentry,'-',"report")
write.xlsx(df,file=filename)
Manu
  • 29
  • 6
  • The slashes of `dateofentry` might be interpreted as subdirectories. File names must not contain `/` and should end with `xlsx` in your case. Try `write.xlsx(df,file="2022-03-02-report.xlsx")` instead – danlooo Mar 09 '22 at 10:27
  • Hi. Thank you. However my main issue is that I will be creating multiple dataframes and so need to distinguish between them. This is the reason I made another variable for date. Even if I remove backslashes, still the code is not recognizing dateofentry as variable. It is considering it as a string. – Manu Mar 09 '22 at 10:32
  • 1
    `dateofentry <- "02-03-2022"; openxlsx::write.xlsx(iris, paste0(dateofentry, "report.xlsx"))` this should work – danlooo Mar 09 '22 at 10:37

0 Answers0