Skip to content

Commit 8e3b6d3

Browse files
authored
tabColour accepts wb_colour() (#500)
* tabColour accepts wb_colour() * use is_wbColour * update NEWS
1 parent a150be0 commit 8e3b6d3

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* `writeData()` calls `force(x)` to evaluate the object before options are set ([#264](https://github.com/ycphs/openxlsx/issues/264))
88

9+
* `tabColour` in `wb_add_worksheet()` now allows passing `wb_colour()`. [500](https://github.com/JanMarvin/openxlsx2/pull/500)
10+
911
## Fixes
1012

1113
* Reading of files with frozen panes and more than one section node was restored. [495](https://github.com/JanMarvin/openxlsx2/pull/495)
@@ -23,7 +25,6 @@
2325
* Do not export `write_data2()` anymore. This was used in development in the early stages of the package and should not be used directly anymore.
2426

2527

26-
2728
***************************************************************************
2829

2930

R/class-workbook.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,11 @@ wbWorkbook <- R6::R6Class(
380380
)
381381

382382
if (!is.null(tabColour)) {
383-
tabColour <- validateColour(tabColour, "Invalid tabColour in add_worksheet.")
383+
if (is_wbColour(tabColour)) {
384+
tabColour <- as.character(tabColour)
385+
} else {
386+
tabColour <- validateColour(tabColour, "Invalid tabColour in add_chartsheet.")
387+
}
384388
}
385389

386390
if (!is.numeric(zoom)) {
@@ -526,7 +530,11 @@ wbWorkbook <- R6::R6Class(
526530
}
527531

528532
if (!is.null(tabColour)) {
529-
tabColour <- validateColour(tabColour, "Invalid tabColour in add_worksheet.")
533+
if (is_wbColour(tabColour)) {
534+
tabColour <- as.character(tabColour)
535+
} else {
536+
tabColour <- validateColour(tabColour, "Invalid tabColour in add_worksheet.")
537+
}
530538
}
531539

532540
if (!is.numeric(zoom)) {

tests/testthat/test-class-color.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ test_that("get()", {
1515
expect_equal(exp, got)
1616

1717
})
18+
19+
test_that("tabColour can be wb_colour()", {
20+
expect_silent(
21+
wb_workbook()$
22+
# wb_colour
23+
add_worksheet(tabColour = wb_colour("green"))$
24+
add_chartsheet(tabColour = wb_colour("green"))$
25+
# colour name
26+
add_worksheet(tabColour = "green")$
27+
add_chartsheet(tabColour = "green")
28+
)
29+
})

0 commit comments

Comments
 (0)