Skip to content

Some colours in *.background.color statements within tab_options result in a Sass error #712

@francisbarton

Description

@francisbarton

*.background.color statements within tab_options result in a Sass error if an R colour name is provided that is not also an HTML colour name.

The docs say that "A color name or a hexadecimal color code should be provided."

Is it possible that only valid HTML colour names, not all R colour names, are acceptable?

library(gt)
library(dplyr, warn.conflicts = FALSE)
data("gtcars")

gtcars %>% 
  filter(mfr == "Aston Martin") %>% 
  gt() %>% 
  tab_source_note(md("*Data from the {gt} package*")) %>% 
  tab_options(
    source_notes.background.color = "grey80")
#> Error in compile_data(sass_input, options): Error: argument `$color` of `red($color)` must be a color
#>         on line 13:5 of ../../../../../Programs/R/library/gt/css/gt_colors.scss, in function `red`
#>         from line 13:5 of ../../../../../Programs/R/library/gt/css/gt_colors.scss, in function `if`
#>         from line 12:11 of ../../../../../Programs/R/library/gt/css/gt_colors.scss, in function `font-color`
#>         from line 281:12 of ../../../../../Programs/R/library/gt/css/gt_styles_default.scss, in mixin `gt-styles`
#>         from line 121:10 of stdin
#> >>     red($color) * 0.299 + green($color) * 0.587 + blue($color) * 0.114 > 186
#>    ----^

This works though (not run)

if (FALSE) {
gtcars %>% 
  filter(mfr == "Aston Martin") %>% 
  gt() %>% 
  tab_source_note(md("*Data from the {gt} package*")) %>% 
  tab_options(
    source_notes.background.color = "cornflowerblue")
}

and this (not run)

if (FALSE) {
gtcars %>% 
  filter(mfr == "Aston Martin") %>% 
  gt() %>% 
  tab_source_note(md("*Data from the {gt} package*")) %>% 
  tab_options(
    source_notes.background.color = "#777777")
}

Created on 2021-02-09 by the reprex package (v1.0.0)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United Kingdom.1252 
#>  ctype    English_United Kingdom.1252 
#>  tz       Europe/London               
#>  date     2021-02-09                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.3)
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.0.3)
#>  checkmate     2.0.0   2020-02-06 [1] CRAN (R 4.0.3)
#>  cli           2.3.0   2021-01-31 [1] CRAN (R 4.0.3)
#>  colorspace    2.0-0   2020-11-11 [1] CRAN (R 4.0.3)
#>  commonmark    1.7     2018-12-01 [1] CRAN (R 4.0.3)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.3)
#>  DBI           1.1.1   2021-01-15 [1] CRAN (R 4.0.3)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.3)
#>  dplyr       * 1.0.4   2021-02-02 [1] CRAN (R 4.0.3)
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.3)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.3)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.3)
#>  generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.3)
#>  ggplot2       3.3.3   2020-12-30 [1] CRAN (R 4.0.3)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.3)
#>  gt          * 0.2.2   2020-08-05 [1] CRAN (R 4.0.3)
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.3)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.3)
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3)
#>  knitr         1.31    2021-01-27 [1] CRAN (R 4.0.3)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.3)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.3)
#>  pillar        1.4.7   2020-11-20 [1] CRAN (R 4.0.3)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.3)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.3)
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.3)
#>  reprex        1.0.0   2021-01-27 [1] CRAN (R 4.0.3)
#>  rlang         0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
#>  rmarkdown     2.6     2020-12-14 [1] CRAN (R 4.0.3)
#>  sass          0.3.1   2021-01-24 [1] CRAN (R 4.0.3)
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.3)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.3)
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.3)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.3)
#>  styler        1.3.2   2020-02-23 [1] CRAN (R 4.0.3)
#>  tibble        3.0.6   2021-01-29 [1] CRAN (R 4.0.3)
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.3)
#>  vctrs         0.3.6   2020-12-17 [1] CRAN (R 4.0.3)
#>  withr         2.4.1   2021-01-26 [1] CRAN (R 4.0.3)
#>  xfun          0.20    2021-01-06 [1] CRAN (R 4.0.3)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.3)
#> 
#> [1] C:/Users/Francis/Programs/R/library
#> [2] C:/Users/Francis/Programs/R/R-4.0.3/library

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions