Skip to content

Commit beb7c0d

Browse files
authored
Merge pull request #502 from JanMarvin/colour_color_pt2
Colour color pt2
2 parents cf3f888 + bcda65c commit beb7c0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+310
-328
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ import(R6)
141141
import(Rcpp)
142142
importFrom(grDevices,bmp)
143143
importFrom(grDevices,col2rgb)
144-
importFrom(grDevices,colours)
144+
importFrom(grDevices,colors)
145145
importFrom(grDevices,dev.copy)
146146
importFrom(grDevices,dev.list)
147147
importFrom(grDevices,dev.off)

NEWS.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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)
9+
* `tabColor` in `wb_add_worksheet()` now allows passing `wb_color()`. [500](https://github.com/JanMarvin/openxlsx2/pull/500)
1010

1111
## Fixes
1212

@@ -24,6 +24,8 @@
2424

2525
* 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.
2626

27+
* Only documentation: `openxlsx2` defaults to american english 'color' from now on. Though, we fully support the previous 'colour'. Users will not have to adjust their code. Our documentation only lists `color`, but you can pass `colour` just the same way you used to. [501](https://github.com/JanMarvin/openxlsx2/pull/501) [502](https://github.com/JanMarvin/openxlsx2/pull/502)
28+
2729

2830
***************************************************************************
2931

@@ -158,7 +160,7 @@
158160

159161
* New argument `startCol` in read to data frame functions `wb_to_df()`, `wb_read()` and `read_xlsx()`. [330](https://github.com/JanMarvin/openxlsx2/issues/330)
160162

161-
* New function `wb_colour()` to ease working with colour vectors used in `openxlsx2` styles. [292](https://github.com/JanMarvin/openxlsx2/issues/292)
163+
* New function `wb_colour()` to ease working with color vectors used in `openxlsx2` styles. [292](https://github.com/JanMarvin/openxlsx2/issues/292)
162164

163165
* Deprecated `get_cell_style()` and `set_cell_style()` in favor of newly introduced wrapper functions `wb_get_cell_style()` and `wb_set_cell_style()`. [306](https://github.com/JanMarvin/openxlsx2/issues/306)
164166

R/asserts.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ match_oneof <- function(x, y, or_null = FALSE, several = FALSE, envir = parent.f
5151
y[m]
5252
}
5353

54-
validate_colour <- function(colour = NULL, or_null = FALSE, envir = parent.frame()) {
55-
sx <- as.character(substitute(colour, envir))
54+
validate_color <- function(color = NULL, or_null = FALSE, envir = parent.frame()) {
55+
sx <- as.character(substitute(color, envir))
5656

57-
if (identical(colour, "none") && or_null) {
57+
if (identical(color, "none") && or_null) {
5858
return(NULL)
5959
}
6060

6161
# returns black
62-
if (is.null(colour)) {
62+
if (is.null(color)) {
6363
if (or_null) return(NULL)
6464
return("FF000000")
6565
}
6666

67-
if (ind <- any(colour %in% grDevices::colours())) {
68-
colour[ind] <- col2hex(colour[ind])
67+
if (ind <- any(color %in% grDevices::colors())) {
68+
color[ind] <- col2hex(color[ind])
6969
}
7070

71-
if (any(!grepl("^#[A-Fa-f0-9]{6}$", colour))) {
72-
msg <- sprintf("`%s` ['%s'] is not a valid colour", sx, colour)
71+
if (any(!grepl("^#[A-Fa-f0-9]{6}$", color))) {
72+
msg <- sprintf("`%s` ['%s'] is not a valid color", sx, color)
7373
stop(simpleError(msg))
7474
}
7575

76-
gsub("^#", "FF", toupper(colour))
76+
gsub("^#", "FF", toupper(color))
7777
}

R/baseXML.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,20 @@ genBaseTheme <- function() {
483483
)
484484
}
485485

486-
gen_databar_extlst <- function(guid, sqref, posColour, negColour, values, border, gradient) {
486+
gen_databar_extlst <- function(guid, sqref, posColor, negColor, values, border, gradient) {
487487
xml <- sprintf('<x14:cfRule type="dataBar" id="{%s}"><x14:dataBar minLength="0" maxLength="100" border="%s" gradient = "%s" negativeBarBorderColorSameAsPositive="0">', guid, border, gradient)
488488

489489
if (is.null(values)) {
490490
xml <- sprintf('<ext uri="{78C0D931-6437-407d-A8EE-F0AAD7539E65}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"><x14:conditionalFormattings><x14:conditionalFormatting xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
491491
%s
492492
<x14:cfvo type="autoMin"/><x14:cfvo type="autoMax"/><x14:borderColor rgb="%s"/><x14:negativeFillColor rgb="%s"/><x14:negativeBorderColor rgb="%s"/><x14:axisColor rgb="FF000000"/>
493-
</x14:dataBar></x14:cfRule><xm:sqref>%s</xm:sqref></x14:conditionalFormatting></x14:conditionalFormattings></ext>', xml, posColour, negColour, negColour, sqref)
493+
</x14:dataBar></x14:cfRule><xm:sqref>%s</xm:sqref></x14:conditionalFormatting></x14:conditionalFormattings></ext>', xml, posColor, negColor, negColor, sqref)
494494
} else {
495495
xml <- sprintf('<ext uri="{78C0D931-6437-407d-A8EE-F0AAD7539E65}" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"><x14:conditionalFormattings><x14:conditionalFormatting xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main">
496496
%s
497497
<x14:cfvo type="num"><xm:f>%s</xm:f></x14:cfvo><x14:cfvo type="num"><xm:f>%s</xm:f></x14:cfvo>
498498
<x14:borderColor rgb="%s"/><x14:negativeFillColor rgb="%s"/><x14:negativeBorderColor rgb="%s"/><x14:axisColor rgb="FF000000"/>
499-
</x14:dataBar></x14:cfRule><xm:sqref>%s</xm:sqref></x14:conditionalFormatting></x14:conditionalFormattings></ext>', xml, values[[1]], values[[2]], posColour, negColour, negColour, sqref)
499+
</x14:dataBar></x14:cfRule><xm:sqref>%s</xm:sqref></x14:conditionalFormatting></x14:conditionalFormattings></ext>', xml, values[[1]], values[[2]], posColor, negColor, negColor, sqref)
500500
}
501501

502502
return(xml)

R/class-chart-sheet.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ wbChartSheet <- R6::R6Class(
2727

2828
#' @description
2929
#' Create a new workbook chart sheet object
30-
#' @param tabColour `character` a tab colour to set
30+
#' @param tabColor `character` a tab color to set
3131
#' @return The `wbChartSheet` object
32-
initialize = function(tabColour = tabColour) {
33-
if (length(tabColour)) {
34-
tabColour <- sprintf('<sheetPr><tabColor rgb="%s"/></sheetPr>', tabColour)
32+
initialize = function(tabColor = tabColor) {
33+
if (length(tabColor)) {
34+
tabColor <- sprintf('<sheetPr><tabColor rgb="%s"/></sheetPr>', tabColor)
3535
} else {
36-
tabColour <- character()
36+
tabColor <- character()
3737
}
3838

39-
self$sheetPr <- tabColour
39+
self$sheetPr <- tabColor
4040
self$sheetViews <- character()
4141
self$pageMargins <- '<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>'
4242
self$drawing <- '<drawing r:id=\"rId1\"/>'

R/class-color.R

+12-32
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @return a `wbColour` object
99
#' @rdname wbColour
1010
#' @export
11-
wb_colour <- function(
11+
wb_color <- function(
1212
name = NULL,
1313
auto = NULL,
1414
indexed = NULL,
@@ -17,7 +17,7 @@ wb_colour <- function(
1717
tint = NULL
1818
) {
1919

20-
if (!is.null(name)) hex <- validate_colour(name)
20+
if (!is.null(name)) hex <- validate_color(name)
2121

2222
z <- c(
2323
auto = auto,
@@ -30,53 +30,33 @@ wb_colour <- function(
3030
if (is.null(z))
3131
z <- c(name = "black")
3232

33+
# wbColour for historical reasons
3334
class(z) <- c("character", "wbColour")
3435
z
3536
}
3637

3738
#' @export
3839
#' @rdname wbColour
3940
#' @usage NULL
40-
wb_color <- wb_colour
41+
wb_colour <- wb_color
4142

4243
is_wbColour <- function(x) inherits(x, "wbColour")
4344

44-
#' takes color and returns colour
45-
#' @param ... ...
46-
#' @returns named colour argument
47-
#' @keywords internal
48-
#' @noRd
49-
standardise_color_names <- function(...) {
50-
51-
got <- ...names()
52-
# can be Colour or colour
53-
got_colour <- which(grepl("color", tolower(got)))
54-
55-
if (length(got_colour)) {
56-
for (got_col in got_colour) {
57-
colour <- got[got_col]
58-
name_color <- stringi::stri_replace_all_fixed(colour, "olor", "olour", )
59-
value_color <- ...elt(got_col)
60-
assign(name_color, value_color, parent.frame())
61-
}
62-
}
63-
}
64-
6545
#' takes colour and returns color
6646
#' @param ... ...
67-
#' @returns named color argument
47+
#' @returns void. assigns an object in the parent frame
6848
#' @keywords internal
6949
#' @noRd
70-
standardize_colour_names <- function(...) {
50+
standardize_color_names <- function(...) {
7151

7252
got <- ...names()
73-
# can be Colour or colour
74-
got_colour <- which(grepl("colour", tolower(got)))
53+
# can be Color or color
54+
got_color <- which(grepl("colour", tolower(got)))
7555

76-
if (length(got_colour)) {
77-
for (got_col in got_colour) {
78-
colour <- got[got_col]
79-
name_color <- stringi::stri_replace_all_fixed(colour, "olour", "olor", )
56+
if (length(got_color)) {
57+
for (got_col in got_color) {
58+
color <- got[got_col]
59+
name_color <- stringi::stri_replace_all_fixed(color, "olour", "olor", )
8060
value_color <- ...elt(got_col)
8161
assign(name_color, value_color, parent.frame())
8262
}

R/class-comment.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ wbComment <- R6::R6Class(
6666
styleShow,
6767
sprintf("Font name: %s\n", unname(unlist(xml_attr(s[[i]], "font", "name")))), ## Font name
6868
sprintf("Font size: %s\n", unname(unlist(xml_attr(s[[i]], "font", "sz")))), ## Font size
69-
sprintf("Font colour: %s\n", gsub("^FF", "#", unname(unlist(xml_attr(s[[i]], "font", "color"))))), ## Font colour
69+
sprintf("Font color: %s\n", gsub("^FF", "#", unname(unlist(xml_attr(s[[i]], "font", "color"))))), ## Font color
7070
"\n\n"
7171
)
7272
}
@@ -111,8 +111,8 @@ wbComment <- R6::R6Class(
111111
#' write_comment(wb, 1, col = "C", row = 10, comment = c2)
112112
#'
113113
#' # write a styled comment with system author
114-
#' s1 <- create_font(b = "true", color = wb_colour(hex = "FFFF0000"), sz = "12")
115-
#' s2 <- create_font(color = wb_colour(hex = "FF000000"), sz = "9")
114+
#' s1 <- create_font(b = "true", color = wb_color(hex = "FFFF0000"), sz = "12")
115+
#' s2 <- create_font(color = wb_color(hex = "FF000000"), sz = "9")
116116
#' c3 <- create_comment(text = c("This Part Bold red\n\n", "This part black"), style = c(s1, s2))
117117
#'
118118
#' write_comment(wb, 1, col = 6, row = 3, comment = c3)

R/class-style_mgr.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
#'
2626
#' ## create and add huge font
2727
#' new_huge_font <- create_font(sz = "20", name = "Arial", b = "1",
28-
#' color = wb_colour(hex = "FFFFFFFF"))
28+
#' color = wb_color(hex = "FFFFFFFF"))
2929
#' wb$styles_mgr$add(new_huge_font, "arial_huge")
3030
#'
3131
#' ## create another font
3232
#' new_font <- create_font(name = "Arial")
3333
#' wb$styles_mgr$add(new_font, "arial")
3434
#'
3535
#' ## create and add new fill
36-
#' new_fill <- create_fill(patternType = "solid", fgColor = wb_colour(hex = "FF00224B"))
36+
#' new_fill <- create_fill(patternType = "solid", fgColor = wb_color(hex = "FF00224B"))
3737
#' wb$styles_mgr$add(new_fill, "blue")
3838
#'
3939
#' # create new style with numfmt enabled

0 commit comments

Comments
 (0)