0

Is there a way to save a manipulated table back into the original Excel file so it can have two sheets? 1. Original 2. Edited

I took an Excel table and removed columns in R; I also filtered out NA values. I am able to save this new table as a new Excel file but I'm trying to save it as a new sheet into the original workbook.

I am currently using the openxlsx package and the write.xlsx() function.

Code:

library(dplyr)
library(magrittr)
filtered <- BD_Providers %>%
  unique() %>%
  select(REF_ERP, UUID) %>%
  filter(!is.na(UUID)) %>%
  filter(!is.na(REF_ERP))
library(openxlsx)
write.xlsx(filtered, file="Table_RFC_UUID.xlsx", sheetName="RFC_UUID")
r2evans
  • 141,215
  • 6
  • 77
  • 149
EAG
  • 59
  • 6
  • `openxlsx` isn't (currently) set up to open an existing workbook and add sheets to it. Your workaround is likely going to be a combination of `openxlsx::read.xlsx` and then create a new one with `wb <- createWorkbook(...)` and `addWorksheet(wb, ...)` calls. – r2evans Apr 08 '20 at 15:27
  • Makes sense. Thanks! – EAG Apr 08 '20 at 15:48

0 Answers0