ソースを参照

more informative error messages when using non-hex CSS colors

tags/v0.3.0
コミット
139fc4b6a2
2個のファイルの変更26行の追加2行の削除
  1. +11
    -2
      R/color.R
  2. +15
    -0
      tests/testthat/test-ggplot2.R

+ 11
- 2
R/color.R ファイルの表示

@@ -96,8 +96,17 @@ prepare_colors <- function(colors = NULL) {
}

full_length_hex <- function(x) {
varname <- substitute(x)
stop_not_hex <- function() {
stop(str_wrap(
"`", deparse(varname), "` is not a hexadecimal color: ", x, ". ",
"If you used valid CSS colors in your xaringan theme, please convert ",
"these colors to hexadecimal form, as this is the format required by ",
"ggplot2."
), call. = FALSE)
}
if (!grepl("^#", x) || grepl("[^#0-9a-fA-F]", x)) {
stop(paste0('"', x, '" is not a hexadecimal color'))
stop_not_hex()
}
x <- sub("^#", "", x)
if (nchar(x) == 3) {
@@ -105,7 +114,7 @@ full_length_hex <- function(x) {
x <- rep(x, each = 2)
x <- paste(x, collapse = "")
} else if (nchar(x) != 6) {
stop(paste0('"', x, '" is not a hexadecimal color'))
stop_not_hex()
}
paste0("#", x)
}

+ 15
- 0
tests/testthat/test-ggplot2.R ファイルの表示

@@ -87,6 +87,21 @@ describe("theme_xaringan()", {
expect_equal(theme$plot.background$colour, "#000022")
expect_equal(theme$plot.background$fill, "#000022")
})

it("throws error for non-hex color functions", {
expect_error(
with_clean_session(function() {
xaringanthemer::style_xaringan(
text_color = "rgb(0, 0, 0)",
outfile = NULL
)
xaringanthemer::theme_xaringan(
text_font_use_google = FALSE,
title_font_use_google = FALSE
)
})
)
})
})

describe("theme_xaringan_inverse()", {

読み込み中…
キャンセル
保存