| library(tidyverse) | |||||
| read_colors <- function(file) { | read_colors <- function(file) { | ||||
| library(dplyr) | |||||
| text <- readLines(file, warn = FALSE) %>% | text <- readLines(file, warn = FALSE) %>% | ||||
| str_subset("#[0-9a-fA-F]{6}") # must be len-6 hex | |||||
| stringr::str_subset("#[0-9a-fA-F]{6}") # must be len-6 hex | |||||
| str_match_all(text, "\\$(.+)\\s*:\\s*(#[0-9a-fA-F]{6});") %>% | |||||
| discard(~ length(.) < 1) %>% | |||||
| map_dfr(~ tibble(name = .[, 2], color = .[, 3])) %>% | |||||
| stringr::str_match_all(text, "\\$(.+)\\s*:\\s*(#[0-9a-fA-F]{6});") %>% | |||||
| purrr::discard(~ length(.) < 1) %>% | |||||
| purrr::map_dfr(~ tibble(name = .[, 2], color = .[, 3])) %>% | |||||
| distinct(name, color) %>% | distinct(name, color) %>% | ||||
| mutate(name = factor(name, unique(name))) | mutate(name = factor(name, unique(name))) | ||||
| } | } | ||||
| show_colors <- function(colors) { | |||||
| show_colors <- function(colors, ...) { | |||||
| ggplot(colors) + | ggplot(colors) + | ||||
| aes(1, 1, fill = color) + | aes(1, 1, fill = color) + | ||||
| geom_tile() + | geom_tile() + | ||||
| facet_wrap(~ name + color) + | |||||
| facet_wrap(~ name + color, ...) + | |||||
| scale_fill_identity() + | scale_fill_identity() + | ||||
| theme_void() | theme_void() | ||||
| } | } |
| --- | |||||
| output: github_document | |||||
| --- | |||||
| <!-- README.md is generated from README.Rmd. Please edit that file --> | |||||
| ```{r, include = FALSE} | |||||
| knitr::opts_chunk$set( | |||||
| collapse = TRUE, | |||||
| comment = "#>", | |||||
| echo = FALSE, | |||||
| warning = FALSE, message = FALSE, | |||||
| fig.path = "docs/" | |||||
| ) | |||||
| ``` | |||||
| # RStudio Themes | |||||
| <!-- badges: start --> | |||||
| <!-- badges: end --> | |||||
| `rstudio-scss` provides SCSS/SASS templates for full RStudio themes for RStudio version 1.2 (and possibly RStudio 1.2+). | |||||
| ## Palettes | |||||
| ```{r palettes, echo=FALSE, results="asis", fig.width=10, fig.height=4} | |||||
| library(ggplot2) | |||||
| source("R/make_functions.R") | |||||
| source("R/show_colors.R") | |||||
| themes <- list( | |||||
| "Solarized" = "_solarized.scss", | |||||
| "Nord" = "_nord.scss", | |||||
| "Oceanic Plus" = "_oceanic-plus.scss" | |||||
| ) | |||||
| for (theme in names(themes)) { | |||||
| theme_file <- fs::path("src", "palettes", themes[[theme]]) | |||||
| colors <- read_colors(theme_file) | |||||
| g <- show_colors(colors, ncol = 8) + | |||||
| ggtitle(theme) + | |||||
| coord_equal() + | |||||
| theme( | |||||
| plot.title = element_text(size = rel(2), hjust = 0.5, margin = margin(t = 20, b = 10)) | |||||
| ) | |||||
| print(g) | |||||
| } | |||||
| ``` |
| <!-- README.md is generated from README.Rmd. Please edit that file --> | |||||
| # RStudio Themes | |||||
| <!-- badges: start --> | |||||
| <!-- badges: end --> | |||||
| `rstudio-scss` provides SCSS/SASS templates for full RStudio themes for | |||||
| RStudio version 1.2 (and possibly RStudio 1.2+). | |||||
| ## Palettes | |||||
| <!-- --><!-- --><!-- --> |