statistikZH / statR

ZH-color-scheme & theme_stat template for ggplot2.
https://statistikzh.github.io/statR/
GNU General Public License v3.0
15 stars 1 forks source link

splitXLSX only use sheetvar as sheetname #19

Closed ThomasKnecht closed 3 years ago

ThomasKnecht commented 3 years ago

I would prefer to only use the sheetvar as sheetname. I have a case now, where the sheetname gets too long if the sheetvar column name as well as the value is used as sheetname. I

function (data, file, sheetvar, ...) { data <- as.data.frame(data) col_name <- rlang::enquo(sheetvar) wb <- openxlsx::createWorkbook(file) sheetvalues <- unique(data[, c(deparse(substitute(sheetvar)))]) for (sheetvalue in sheetvalues) { insert_worksheet(as.data.frame(data %>% dplyr::filter((!!col_name) == sheetvalue) %>% ungroup()), wb, sheetname = paste(deparse(substitute(sheetvar)), sheetvalue, sep = ","), ...) } openxlsx::worksheetOrder(wb) <- rev(openxlsx::worksheetOrder(wb)) openxlsx::saveWorkbook(wb, paste(file, ".xlsx", sep = ""), overwrite = TRUE) }

i would suggest the following solution:

function (data, file, sheetvar, ...) { data <- as.data.frame(data) col_name <- rlang::enquo(sheetvar) wb <- openxlsx::createWorkbook(file) sheetvalues <- unique(data[, c(deparse(substitute(sheetvar)))]) for (sheetvalue in sheetvalues) { insert_worksheet(as.data.frame(data %>% dplyr::filter((!!col_name) == sheetvalue) %>% ungroup()), wb, sheetname = sheetvalue, ...) } openxlsx::worksheetOrder(wb) <- rev(openxlsx::worksheetOrder(wb)) openxlsx::saveWorkbook(wb, paste(file, ".xlsx", sep = ""), overwrite = TRUE) }

mdllz commented 3 years ago

Thanks @ThomasKnecht! Your suggestion is now implemented.