I am trying to replace the data in a few sheets of an existing excel workbook (there are several sheets with formulae in it which remain untouched). I am using the package XLConnect for the same. The idea is to read an existing workbook , clear the data in the required sheets and then write new dataframes in to them. After this, the file is saved both as the initial version as well as another version with the date. However the syntax saveWorkbook is taking a long time to execute and in the end is throwing up the following error Error: OutOfMemoryError (Java): Java heap space
I installed rJava and ran the following as well: options(java.parameters = "-Xmx2048m")
Is there any alternate way to do it?
Following is the code:
xlWb <- loadWorkbook("C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_Template.xlsx")
wbnames <- as.vector(getSheets(xlWb)) ##sheetNames
clearSheet(xlWb, sheet= c("Dept Var to Prior Day-FC RDC", "Dept Var to Prior Day-BP UDC", "Dept Var to Prior Day-BP", "Dept Var to Prior Day - FC UDC", "Drop_Data_DB2", "Forecasts"))
writeWorksheet(xlWb,list(i1= rdc_finalsorted, i2= udc_finalsorted, i3= rdc_bpr_finalsorted, i4= udc_fcs_finalsorted, i5= data, i6= forecast) , sheet= c("Dept Var to Prior Day-FC RDC", "Dept Var to Prior Day-BP UDC", "Dept Var to Prior Day-BP", "Dept Var to Prior Day - FC UDC", "Drop_Data_DB2", "Forecasts"), startRow =1, startCol =1, header= T, rownames = NULL)
saveWorkbook(xlWb,"C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_Template.xlsx")
saveWorkbook(xlWb, paste0("C:\\\\Users\\z003b1d\\Desktop\\Drop_Data_DB2_",Sys.Date(),".xlsx"))