diff --git a/R/write_xlsx.R b/R/write_xlsx.R index ae5dcf4a1..f71c025c0 100644 --- a/R/write_xlsx.R +++ b/R/write_xlsx.R @@ -46,7 +46,7 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) { ## set scientific notation penalty - arguments <- c(ls(), "creator", "sheet_name", "grid_lines", + arguments <- c(ls(), "creator", "sheet", "sheet_name", "grid_lines", "tab_color", "tab_colour", "zoom", "header", "footer", "even_header", "even_footer", "first_header", "first_footer", "start_col", "start_row", "total_row", @@ -137,13 +137,14 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) { sheetName <- "Sheet 1" - if ("sheet_name" %in% names(params)) { + if (any(c("sheet_name", "sheet") %in% names(params))) { + + sheetName <- as.character(params$sheet_name %||% params$sheet) + if (any(nchar(params$sheet_name) > 31)) { stop("sheet_name too long! Max length is 31 characters.") } - sheetName <- as.character(params$sheet_name) - if (inherits(x, "list") && (length(sheetName) == length(x))) { names(x) <- sheetName } diff --git a/tests/testthat/test-write.R b/tests/testthat/test-write.R index b07cbbc90..9856f079c 100644 --- a/tests/testthat/test-write.R +++ b/tests/testthat/test-write.R @@ -1233,3 +1233,9 @@ test_that("non consecutive columns do not overlap", { expect_equal(exp, got) }) + +test_that("sheet is a valid argument in write_xlsx", { + wb1 <- write_xlsx(x = mtcars, sheet_name = "data") + wb2 <- write_xlsx(x = mtcars, sheet = "data") + expect_equal(wb1$get_sheet_names(), wb2$get_sheet_names()) +})