Last active
February 1, 2023 18:37
-
-
Save mattgalbraith/8da6023ee8971073d1c9b15e35c85698 to your computer and use it in GitHub Desktop.
R function to export tables in XLSX format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Excel export function | |
export_excel <- function(named_list, filename = "") { | |
wb <- openxlsx::createWorkbook() | |
## Loop through the list of split tables as well as their names | |
## and add each one as a sheet to the workbook | |
Map(function(data, name){ | |
openxlsx::addWorksheet(wb, name) | |
openxlsx::writeData(wb, name, data) | |
}, named_list, names(named_list)) | |
## Save workbook to working directory | |
openxlsx::saveWorkbook(wb, file = here("results", paste0(out_file_prefix, filename, ".xlsx")), overwrite = TRUE) | |
cat("Saved as:", here("results", paste0(out_file_prefix, filename, ".xlsx"))) | |
} # end of function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need to update to make output filename more generic