rstudio / thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
https://rstudio.github.io/thematic/
Other
244 stars 10 forks source link

thematic_rmd "adjust_color" function fails when update_geom_default is set by referring to a variable. #151

Open SimonCoulombe opened 4 months ago

SimonCoulombe commented 4 months ago

Describe the problem

thematic_rmd() function may lead to an error with adjust_color when update_geom_default has been set by referring to a string variable containing the color name.

wrapping that string variable between {{}} solves the issue, but I'm not sure why this is necessary.

---
title: "title"
author: "author"
date: "2024-06-04"
output:
  html_document:
    theme:
      version: 5
      preset: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dplyr)
library(thematic)

thematic::thematic_rmd()
favorite_color = "#0000F0"

# option 1 -- this knits
#ggplot2::update_geom_defaults("point", ggplot2::aes(color = "blue"))

# options 2 -- this crashes  
# Error in `adjust_color()`:  ! Internal error: adjust_color() expects an input of length 1
ggplot2::update_geom_defaults("point", ggplot2::aes(color = favorite_color))

# option 3 -- this knits
#ggplot2::update_geom_defaults("point", ggplot2::aes(color = {{favorite_color}}))

iris %>%
  ggplot(aes(x= Sepal.Width, y= Sepal.Length)) + 
  geom_point()
sessioninfo::session_info()


### Session Info

<details>
<pre><code>
sessioninfo::session_info()
## - Session info ---------------------------------------------------------------
##  setting  value
##  version  R version 4.0.2 (2020-06-22)
##  os       OpenShift Enterprise
##  system   x86_64, linux-gnu
##  ui       X11
##  language (EN)
##  collate  en_CA
##  ctype    en_CA
##  tz       America/Toronto
##  date     2024-06-04
##  pandoc   3.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown)
## 
## - Packages -------------------------------------------------------------------
##  ! package     * version    date (UTC) lib source
##  P bslib         0.7.0      2024-03-29 [?] RSPM (R 4.0.5)
##  P cachem        1.0.8      2023-05-01 [?] RSPM (R 4.0.5)
##  P cli           3.6.2      2023-12-11 [?] RSPM (R 4.0.5)
##    colorspace    2.1-0      2023-01-23 [1] CRAN (R 4.0.2)
##  P digest        0.6.35     2024-03-11 [?] RSPM (R 4.0.5)
##  P dplyr       * 1.1.4      2023-11-17 [?] RSPM (R 4.0.5)
##  P evaluate      0.23       2023-11-01 [?] RSPM (R 4.0.5)
##  P fansi         1.0.6      2023-12-08 [?] RSPM (R 4.0.5)
##    farver        2.1.1      2022-07-06 [1] CRAN (R 4.0.2)
##  P fastmap       1.1.1      2023-02-24 [?] RSPM (R 4.0.5)
##  P generics      0.1.3      2022-07-05 [?] RSPM (R 4.0.5)
##    ggplot2     * 3.5.0      2024-02-23 [1] CRAN (R 4.0.2)
##  P glue          1.7.0      2024-01-09 [?] RSPM (R 4.0.5)
##    gtable        0.3.4      2023-08-21 [1] CRAN (R 4.0.2)
##  P highr         0.10       2022-12-22 [?] RSPM (R 4.0.5)
##  P htmltools     0.5.8.1    2024-04-04 [?] CRAN (R 4.0.2)
##  P jquerylib     0.1.4      2021-04-26 [?] RSPM (R 4.0.4)
##  P jsonlite      1.8.8      2023-12-04 [?] RSPM (R 4.0.5)
##  P knitr         1.46       2024-04-06 [?] CRAN (R 4.0.2)
##    labeling      0.4.3      2023-08-29 [1] CRAN (R 4.0.2)
##    lattice       0.20-41    2020-04-02 [2] CRAN (R 4.0.2)
##  P lifecycle     1.0.4      2023-11-07 [?] RSPM (R 4.0.5)
##  P magrittr      2.0.3      2022-03-30 [?] RSPM (R 4.0.5)
##    munsell       0.5.1      2024-04-01 [1] CRAN (R 4.0.2)
##  P pillar        1.9.0      2023-03-22 [?] RSPM (R 4.0.5)
##  P pkgconfig     2.0.3      2019-09-22 [?] RSPM (R 4.0.3)
##  P R6            2.5.1      2021-08-19 [?] RSPM (R 4.0.5)
##  P ragg          1.3.0      2024-03-13 [?] RSPM (R 4.0.5)
##  P rlang         1.1.3      2024-01-10 [?] RSPM (R 4.0.5)
##  P rmarkdown     2.26       2024-03-05 [?] RSPM (R 4.0.5)
##  P rstudioapi    0.16.0     2024-03-24 [?] CRAN (R 4.0.5)
##  P sass          0.4.9      2024-03-15 [?] RSPM (R 4.0.5)
##    scales        1.3.0      2023-11-28 [1] CRAN (R 4.0.2)
##  P sessioninfo   1.2.2      2021-12-06 [?] RSPM (R 4.0.5)
##  P systemfonts   1.0.6      2024-03-07 [?] RSPM (R 4.0.5)
##  P textshaping   0.3.7      2023-10-09 [?] RSPM (R 4.0.5)
##    thematic    * 0.1.5.9000 2024-06-04 [1] Github (rstudio/thematic@b7ec742)
##  P tibble        3.2.1      2023-03-20 [?] RSPM (R 4.0.5)
##  P tidyselect    1.2.1      2024-03-11 [?] RSPM (R 4.0.5)
##  P utf8          1.2.4      2023-10-22 [?] RSPM (R 4.0.5)
##  P vctrs         0.6.5      2023-12-01 [?] RSPM (R 4.0.5)
##  P withr         3.0.0      2024-01-16 [?] RSPM (R 4.0.5)
##  P xfun          0.43       2024-03-25 [?] CRAN (R 4.0.5)
##  P yaml          2.3.8      2023-12-11 [?] RSPM (R 4.0.5)
## 
##  [1] /devroot/sandbox/EG66451/git/adhoc/renv/library/R-4.0/x86_64-pc-linux-gnu
##  [2] /opt/R/4.0.2/lib/R/library
##  [3] /devroot/sandbox/EG66451/R/x86_64-pc-linux-gnu-library/4.0
## 
##  P -- Loaded and on-disk path mismatch.
## 
## -------------------------------------
</code></pre>
</details>