Skip to content

Commit

Permalink
[write_xlsx] supply sheetName for single argument. closes #711 (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 1, 2023
1 parent a0f62ef commit 4f15d2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/write_xlsx.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@ write_xlsx <- function(x, file, as_table = FALSE, ...) {


## If a list is supplied write to individual worksheets using names if available
if (!inherits(x, "list"))
if (!inherits(x, "list")) {
x <- list(x)
names(x) <- sheetName
}

nms <- names(x)
nSheets <- length(x)
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-save.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,13 @@ test_that("escaping of inlinestrings works", {
expect_equal(exp, got)

})

test_that("write_xlsx() works", {

tmp <- temp_xlsx()
write_xlsx(mtcars, tmp, sheet_name = "test")
exp <- c(test = "test")
got <- wb_load(tmp)$get_sheet_names()
expect_equal(exp, got)

})

0 comments on commit 4f15d2f

Please sign in to comment.