From ee9066627b22d77765c780e9b821c50f52a1c8b4 Mon Sep 17 00:00:00 2001 From: Matthew Stern <54633946+tallishmatt@users.noreply.github.com> Date: Fri, 2 Apr 2021 22:35:07 -0500 Subject: [PATCH 01/83] set up env and font registry `cmapplot_global` env initializes with "sans" (e.g. Arial) as default font. .onLoad uses systemfonts pkg to register Whitney if available and overwrite fonts as Whitney instead. the `display_cmap_fonts()` test function is updated to call on the new `cmapplot_global` env rather than the `cmapplot_globals` list. --- R/cmapplot.R | 184 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 115 insertions(+), 69 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 01090bc0..a17d66e9 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -17,6 +17,26 @@ #' @keywords internal "_PACKAGE" + +# establish location for cmapplot global variables +cmapplot_global <- new.env(parent = emptyenv()) + +# set up default font handling +# (overridden if local machine has Whitney in .onLoad) +cmapplot_global$use_whitney <- FALSE +cmapplot_global$font <- list( + strong = list(family = "sans", face = "bold"), + regular = list(family = "sans", face = "plain"), + light = list(family = "sans", face = "plain")) + +# establish font sizes +cmapplot_global$fsize <- list( + S = 11, + M = 14, + L = 17 +) + + #'cmapplot global variables #' #'A list of predefined variables for use by the cmapplot package and its users. @@ -134,78 +154,104 @@ cmapplot_globals <- list( ## Update fonts based on system -- *must* be done with .onLoad() +#' @import systemfonts .onLoad <- function(...) { - # Check for Whitney - all_fonts <- sysfonts::font_files() - whitney_fonts <- all_fonts[all_fonts$family %in% c("Whitney Medium", "Whitney Book", "Whitney Semibold") & all_fonts$face=="Regular", ] - cmapplot_globals$use_whitney <<- length(whitney_fonts$family) >= 3 - - # Font handling for Windows users - if (.Platform$OS.type == "windows") { - - # Use Whitney if available - if (cmapplot_globals$use_whitney) { - # Add fonts to R - grDevices::windowsFonts( - `Whitney Medium` = grDevices::windowsFont("Whitney Medium"), - `Whitney Book` = grDevices::windowsFont("Whitney Book"), - `Whitney Semibold` = grDevices::windowsFont("Whitney Semibold") - ) - - # Update font variables - cmapplot_globals$font <<- list( - strong = list(family = "Whitney Semibold", face = "plain"), - regular = list(family = "Whitney Medium", face = "plain"), - light = list(family = "Whitney Book", face = "plain") - ) - - # Otherwise, use Calibri - } else { - packageStartupMessage( - "WARNING: Whitney is not installed on this PC, so CMAP theme will default to Calibri" - ) - # Add fonts to R - grDevices::windowsFonts( - `Calibri` = grDevices::windowsFont("Calibri"), - `Calibri Light` = grDevices::windowsFont("Calibri Light") - ) - - # Update font variables - cmapplot_globals$font <<- list( - strong = list(family = "Calibri", face = "bold"), - regular = list(family = "Calibri", face = "plain"), - light = list(family = "Calibri Light", face = "plain") - ) - } - - # Font handling for macOS/Linux/Unix + # check for Whitney + all_fonts <- systemfonts::system_fonts() + whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] + assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_global) + + if(get("use_whitney", envir = cmapplot_global)){ + # Register all Whitney fonts + # note: this registers italic fonts as variants of core fonts and as standalone fonts, + # so there is some duplication. + whitney_fonts <- select(filter(all_fonts, family == "Whitney"), name, path) + purrr::walk2(whitney_fonts$name, whitney_fonts$path, register_font) + + # Update font variables + assign("font", + list( + strong = list(family = "Whitney-Semibold", face = "plain"), + regular = list(family = "Whitney-Medium", face = "plain"), + light = list(family = "Whitney-Book", face = "plain")), + envir = cmapplot_global) } else { - - # Use Whitney if available - if (cmapplot_globals$use_whitney) { - # Add fonts to R - grDevices::X11Fonts( - `Whitney Medium` = grDevices::X11Font("-*-whitney-medium-%s-*-*-%d-*-*-*-*-*-*-*"), - `Whitney Book` = grDevices::X11Font("-*-whitney-book-%s-*-*-%d-*-*-*-*-*-*-*"), - `Whitney Semibold` = grDevices::X11Font("-*-whitney-semibold-%s-*-*-%d-*-*-*-*-*-*-*") - ) - - # Update font variables - cmapplot_globals$font <<- list( - strong = list(family = "Whitney Semibold", face = "plain"), - regular = list(family = "Whitney Medium", face = "plain"), - light = list(family = "Whitney Book", face = "plain") - ) - - # Otherwise, stick to Arial (set prior to .onLoad()) - } else { - packageStartupMessage( - "WARNING: Whitney is not installed on this system, so CMAP theme will default to Arial" - ) - } + packageStartupMessage( + "WARNING: Whitney is not installed on this machine, so CMAP theme will use your default sans-Serif font" + ) } + # # Check for Whitney + # all_fonts <- sysfonts::font_files() + # whitney_fonts <- all_fonts[all_fonts$family %in% c("Whitney Medium", "Whitney Book", "Whitney Semibold") & all_fonts$face=="Regular", ] + # cmapplot_globals$use_whitney <<- length(whitney_fonts$family) >= 3 + # + # # Font handling for Windows users + # if (.Platform$OS.type == "windows") { + # + # # Use Whitney if available + # if (cmapplot_globals$use_whitney) { + # # Add fonts to R + # grDevices::windowsFonts( + # `Whitney Medium` = grDevices::windowsFont("Whitney Medium"), + # `Whitney Book` = grDevices::windowsFont("Whitney Book"), + # `Whitney Semibold` = grDevices::windowsFont("Whitney Semibold") + # ) + # + # # Update font variables + # cmapplot_globals$font <<- list( + # strong = list(family = "Whitney Semibold", face = "plain"), + # regular = list(family = "Whitney Medium", face = "plain"), + # light = list(family = "Whitney Book", face = "plain") + # ) + # + # # Otherwise, use Calibri + # } else { + # packageStartupMessage( + # "WARNING: Whitney is not installed on this PC, so CMAP theme will default to Calibri" + # ) + # # Add fonts to R + # grDevices::windowsFonts( + # `Calibri` = grDevices::windowsFont("Calibri"), + # `Calibri Light` = grDevices::windowsFont("Calibri Light") + # ) + # + # # Update font variables + # cmapplot_globals$font <<- list( + # strong = list(family = "Calibri", face = "bold"), + # regular = list(family = "Calibri", face = "plain"), + # light = list(family = "Calibri Light", face = "plain") + # ) + # } + # + # # Font handling for macOS/Linux/Unix + # } else { + # + # # Use Whitney if available + # if (cmapplot_globals$use_whitney) { + # # Add fonts to R + # grDevices::X11Fonts( + # `Whitney Medium` = grDevices::X11Font("-*-whitney-medium-%s-*-*-%d-*-*-*-*-*-*-*"), + # `Whitney Book` = grDevices::X11Font("-*-whitney-book-%s-*-*-%d-*-*-*-*-*-*-*"), + # `Whitney Semibold` = grDevices::X11Font("-*-whitney-semibold-%s-*-*-%d-*-*-*-*-*-*-*") + # ) + # + # # Update font variables + # cmapplot_globals$font <<- list( + # strong = list(family = "Whitney Semibold", face = "plain"), + # regular = list(family = "Whitney Medium", face = "plain"), + # light = list(family = "Whitney Book", face = "plain") + # ) + # + # # Otherwise, stick to Arial (set prior to .onLoad()) + # } else { + # packageStartupMessage( + # "WARNING: Whitney is not installed on this system, so CMAP theme will default to Arial" + # ) + # } + # } + # Load CMAP preferred default.aes (can't be done until fonts are specified) cmapplot_globals$default_aes_cmap <<- init_cmap_default_aes() @@ -220,8 +266,8 @@ display_cmap_fonts <- function() { graphics::plot(c(0,2), c(0,6), type="n", xlab="", ylab="") draw.me <- function(name, font, size, placement){ - thisfont <- cmapplot_globals$font[[font]] - thissize <- cmapplot_globals$fsize[[size]] + thisfont <- cmapplot_global$font[[font]] + thissize <- cmapplot_global$fsize[[size]] graphics::par(family=thisfont$family, font=ifelse(thisfont$face == "bold", 2, 1)) From 972f828e6a245acea83757766fd57eb8b8945503 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 2 Apr 2021 23:21:11 -0500 Subject: [PATCH 02/83] tweak --- R/cmapplot.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index a17d66e9..0bc3885a 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -163,11 +163,11 @@ cmapplot_globals <- list( assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_global) if(get("use_whitney", envir = cmapplot_global)){ - # Register all Whitney fonts - # note: this registers italic fonts as variants of core fonts and as standalone fonts, - # so there is some duplication. + # Register all Whitney fonts (note: this registers italic fonts both as + # variants of core fonts and as standalone fonts, so there is some + # duplication.) whitney_fonts <- select(filter(all_fonts, family == "Whitney"), name, path) - purrr::walk2(whitney_fonts$name, whitney_fonts$path, register_font) + purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) # Update font variables assign("font", From 12e15cb1442a8b7e058485ef1531ff072dae13f7 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 2 Apr 2021 23:52:49 -0500 Subject: [PATCH 03/83] revert back to `globals` gave up on new cmap_global nomenclature--too many references throughout package to update. Converted remaining items from the list to the environment. --- R/cmapplot.R | 259 ++++++++++++++++-------------------------------- R/default_aes.R | 11 ++ R/theme_cmap.R | 17 ++-- 3 files changed, 104 insertions(+), 183 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 0bc3885a..0d693809 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -18,101 +18,32 @@ "_PACKAGE" + # establish location for cmapplot global variables -cmapplot_global <- new.env(parent = emptyenv()) +cmapplot_globals <- new.env(parent = emptyenv()) # set up default font handling # (overridden if local machine has Whitney in .onLoad) -cmapplot_global$use_whitney <- FALSE -cmapplot_global$font <- list( +cmapplot_globals$use_whitney <- FALSE +cmapplot_globals$font <- list( strong = list(family = "sans", face = "bold"), regular = list(family = "sans", face = "plain"), light = list(family = "sans", face = "plain")) # establish font sizes -cmapplot_global$fsize <- list( +cmapplot_globals$fsize <- list( S = 11, M = 14, L = 17 ) - -#'cmapplot global variables -#' -#'A list of predefined variables for use by the cmapplot package and its users. -#'It includes commonly used colors, font and font size specifications, and a -#'list of constants which aid in drawing cmap-themed plots. -#' -#'@section Plot Constants: The only portion of these global variables of -#' interest to the user is \code{cmapplot_globals$consts}, a list of default -#' constants that set certain plot aesthetics. Units of all plot constants are -#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be -#' overridden) in \code{\link{finalize_plot}}: these are marked below with an -#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: -#' these are marked with \strong{T}. -#' -#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn -#' vertically or horizontally with the \code{hline, vline} args of -#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This -#' thinner-width line is drawn vertically or horizontally with the -#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item -#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. -#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. -#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but -#' not overridable in either context. (Modify by setting the size explicitly in -#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: -#' The width of the line above the plot. \strong{(F)} \item -#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} -#' \item \code{margin_topline_t}: The margin between the top edge of the image -#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin -#' between the top line and the title. \strong{(F)} \item -#' \code{margin_title_b}: The margin between the title and the caption when -#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: -#' The margin between the bottom of the caption and the bottom edge of the -#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top -#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item -#' \code{margin_legend_i}: The margin between legends (this only applies in -#' plots with two or more legends and does not affect legend spacing on plots -#' with single legends that have multiple rows). \strong{(T, F)} \item -#' \code{margin_legend_b}: The margin between the bottom of the legend and the -#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin -#' between the bottom of the plot and the bottom edge of the image (or top of -#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the -#' left edge of the image and the title and caption, when the sidebar exists. -#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: -#' The margin between the left edge of the plot and the sodebar. \strong{(F)} -#' \item \code{margin_plot_r}: The margin between the right edge of the plot -#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding -#' between the plot and its right-hand drawing extent. Override this based on -#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: -#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text -#' leading for Caption text. \strong{(F)} } -#' -#'@export -cmapplot_globals <- list( - - ## Colors - colors = list( +## Colors +cmapplot_globals$colors <- list( blackish = "#222222" - ), - - ## Font sizes - fsize = list( - S = 11, - M = 14, - L = 17 - ), - - ## Base typefaces -- modified later by .onLoad() - font = list( - strong = list(family = "Arial", face = "bold"), - regular = list(family = "Arial", face = "plain"), - light = list(family = "Arial", face = "plain") - ), - use_whitney = FALSE, + ) - ## Establish plotting constants in bigpts (1/72 of inch) - consts = list( +## Establish plotting constants in bigpts (1/72 of inch) +cmapplot_globals$consts = list( lwd_gridline = 0.3, lwd_strongline = 1, lwd_plotline = 3, @@ -132,25 +63,7 @@ cmapplot_globals <- list( margin_panel_r = 10, leading_title = 1, leading_caption = 1 - ), - - # list of geoms whose aesthetics will be customized - geoms_that_change = c( - "Label", - "Line", - "Text", - "TextLast", - "PointLast", - "RecessionsText" - ), - - # empty location for loading in preferred aesthetics during `.onLoad` - default_aes_cmap = NULL, - - # empty location for caching existing aesthetics during `.onLoad` - default_aes_cached = NULL - -) + ) ## Update fonts based on system -- *must* be done with .onLoad() @@ -160,9 +73,9 @@ cmapplot_globals <- list( # check for Whitney all_fonts <- systemfonts::system_fonts() whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] - assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_global) + assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_globals) - if(get("use_whitney", envir = cmapplot_global)){ + if(get("use_whitney", envir = cmapplot_globals)){ # Register all Whitney fonts (note: this registers italic fonts both as # variants of core fonts and as standalone fonts, so there is some # duplication.) @@ -175,99 +88,40 @@ cmapplot_globals <- list( strong = list(family = "Whitney-Semibold", face = "plain"), regular = list(family = "Whitney-Medium", face = "plain"), light = list(family = "Whitney-Book", face = "plain")), - envir = cmapplot_global) + envir = cmapplot_globals) } else { packageStartupMessage( "WARNING: Whitney is not installed on this machine, so CMAP theme will use your default sans-Serif font" ) } - # # Check for Whitney - # all_fonts <- sysfonts::font_files() - # whitney_fonts <- all_fonts[all_fonts$family %in% c("Whitney Medium", "Whitney Book", "Whitney Semibold") & all_fonts$face=="Regular", ] - # cmapplot_globals$use_whitney <<- length(whitney_fonts$family) >= 3 - # - # # Font handling for Windows users - # if (.Platform$OS.type == "windows") { - # - # # Use Whitney if available - # if (cmapplot_globals$use_whitney) { - # # Add fonts to R - # grDevices::windowsFonts( - # `Whitney Medium` = grDevices::windowsFont("Whitney Medium"), - # `Whitney Book` = grDevices::windowsFont("Whitney Book"), - # `Whitney Semibold` = grDevices::windowsFont("Whitney Semibold") - # ) - # - # # Update font variables - # cmapplot_globals$font <<- list( - # strong = list(family = "Whitney Semibold", face = "plain"), - # regular = list(family = "Whitney Medium", face = "plain"), - # light = list(family = "Whitney Book", face = "plain") - # ) - # - # # Otherwise, use Calibri - # } else { - # packageStartupMessage( - # "WARNING: Whitney is not installed on this PC, so CMAP theme will default to Calibri" - # ) - # # Add fonts to R - # grDevices::windowsFonts( - # `Calibri` = grDevices::windowsFont("Calibri"), - # `Calibri Light` = grDevices::windowsFont("Calibri Light") - # ) - # - # # Update font variables - # cmapplot_globals$font <<- list( - # strong = list(family = "Calibri", face = "bold"), - # regular = list(family = "Calibri", face = "plain"), - # light = list(family = "Calibri Light", face = "plain") - # ) - # } - # - # # Font handling for macOS/Linux/Unix - # } else { - # - # # Use Whitney if available - # if (cmapplot_globals$use_whitney) { - # # Add fonts to R - # grDevices::X11Fonts( - # `Whitney Medium` = grDevices::X11Font("-*-whitney-medium-%s-*-*-%d-*-*-*-*-*-*-*"), - # `Whitney Book` = grDevices::X11Font("-*-whitney-book-%s-*-*-%d-*-*-*-*-*-*-*"), - # `Whitney Semibold` = grDevices::X11Font("-*-whitney-semibold-%s-*-*-%d-*-*-*-*-*-*-*") - # ) - # - # # Update font variables - # cmapplot_globals$font <<- list( - # strong = list(family = "Whitney Semibold", face = "plain"), - # regular = list(family = "Whitney Medium", face = "plain"), - # light = list(family = "Whitney Book", face = "plain") - # ) - # - # # Otherwise, stick to Arial (set prior to .onLoad()) - # } else { - # packageStartupMessage( - # "WARNING: Whitney is not installed on this system, so CMAP theme will default to Arial" - # ) - # } - # } - # Load CMAP preferred default.aes (can't be done until fonts are specified) - cmapplot_globals$default_aes_cmap <<- init_cmap_default_aes() + assign("default_aes_cmap", + init_cmap_default_aes(), + env = cmapplot_globals) # Cache existing default.aes - cmapplot_globals$default_aes_cached <<- fetch_current_default_aes() + assign("default_aes_cached", + fetch_current_default_aes(), + env = cmapplot_globals) } # Font spec visualization helper function --------------------------------- +#' Font visualization test +#' +#' This internal function uses base R graphics to display the five text variants +#' that should show up on a cmap themed graphic - and what fonts the package is +#' planning to use to display them. +#' +#' @noRd display_cmap_fonts <- function() { graphics::plot(c(0,2), c(0,6), type="n", xlab="", ylab="") draw.me <- function(name, font, size, placement){ - thisfont <- cmapplot_global$font[[font]] - thissize <- cmapplot_global$fsize[[size]] + thisfont <- cmapplot_globals$font[[font]] + thissize <- cmapplot_globals$fsize[[size]] graphics::par(family=thisfont$family, font=ifelse(thisfont$face == "bold", 2, 1)) @@ -354,3 +208,58 @@ gg_lwd_convert <- function(value, unit = "bigpts") { value_out / .lwd ) } + + +#'cmapplot global variables +#' +#'A list of predefined variables for use by the cmapplot package and its users. +#'It includes commonly used colors, font and font size specifications, and a +#'list of constants which aid in drawing cmap-themed plots. +#' +#'@section Plot Constants: The only portion of these global variables of +#' interest to the user is \code{cmapplot_globals$consts}, a list of default +#' constants that set certain plot aesthetics. Units of all plot constants are +#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be +#' overridden) in \code{\link{finalize_plot}}: these are marked below with an +#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: +#' these are marked with \strong{T}. +#' +#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn +#' vertically or horizontally with the \code{hline, vline} args of +#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This +#' thinner-width line is drawn vertically or horizontally with the +#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item +#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. +#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. +#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but +#' not overridable in either context. (Modify by setting the size explicitly in +#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: +#' The width of the line above the plot. \strong{(F)} \item +#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} +#' \item \code{margin_topline_t}: The margin between the top edge of the image +#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin +#' between the top line and the title. \strong{(F)} \item +#' \code{margin_title_b}: The margin between the title and the caption when +#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: +#' The margin between the bottom of the caption and the bottom edge of the +#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top +#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item +#' \code{margin_legend_i}: The margin between legends (this only applies in +#' plots with two or more legends and does not affect legend spacing on plots +#' with single legends that have multiple rows). \strong{(T, F)} \item +#' \code{margin_legend_b}: The margin between the bottom of the legend and the +#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin +#' between the bottom of the plot and the bottom edge of the image (or top of +#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the +#' left edge of the image and the title and caption, when the sidebar exists. +#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: +#' The margin between the left edge of the plot and the sodebar. \strong{(F)} +#' \item \code{margin_plot_r}: The margin between the right edge of the plot +#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding +#' between the plot and its right-hand drawing extent. Override this based on +#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: +#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text +#' leading for Caption text. \strong{(F)} } +#' +#'@export +cmapplot_globals_OLD <- list() diff --git a/R/default_aes.R b/R/default_aes.R index 4cf716d8..0329588e 100644 --- a/R/default_aes.R +++ b/R/default_aes.R @@ -1,3 +1,14 @@ +# list of all geoms whose aesthetics will be customized +cmapplot_globals$geoms_that_change <- c( + "Label", + "Line", + "Text", + "TextLast", + "PointLast", + "RecessionsText" +) + + #' Initialize CMAP `default_aes` values #' #' Internal function to load in default aesthetics for modified geoms. diff --git a/R/theme_cmap.R b/R/theme_cmap.R index 99f2fac3..a2e1c716 100644 --- a/R/theme_cmap.R +++ b/R/theme_cmap.R @@ -7,8 +7,8 @@ #'undesireable outcomes in a ggplot that also invokes \code{coord_flip()}. Under #'the hood, \code{theme_cmap(xlab = "foo")} both sets \code{ggplot2::xlab = #'"foo"} and 'turns on' the ggplot theme element \code{axis.title.x}. With -#'\code{coord_flip()}, the xlab travels with the data (becoming the ylab) but the -#'theme modifier stays on the x axis. To solve this, rewrite your ggplot +#'\code{coord_flip()}, the xlab travels with the data (becoming the ylab) but +#'the theme modifier stays on the x axis. To solve this, rewrite your ggplot #'construction to avoid \code{coord_flip()} or manually turn off and on the #'correct elements from ggplot2's \code{\link[ggplot2]{theme}} function in the #'\code{...} of this function. @@ -20,10 +20,11 @@ #' \code{coord_flip()}. #'@param hline,vline Numeric, the location of a strong horizontal or vertical #' line to be added to the plot. Use \code{hline = 0}, for example, to place a -#' line at y = 0 to differentiate between positive and negative values. The width -#' of this line is determined by \code{cmapplot_globals$lwd_strongline}. Note that -#' on most displays the difference between this line and gridlines is impossible -#' to discern in R. The difference will be visible upon export. +#' line at y = 0 to differentiate between positive and negative values. The +#' width of this line is determined by +#' \code{cmapplot_globals$consts$lwd_strongline}. Note that on most displays +#' the difference between this line and gridlines is impossible to discern in +#' R. The difference will be visible upon export. #'@param gridlines Char, the grid lines to be displayed on the chart. If left as #' default, horizontal grid lines will be displayed while vertical grid lines #' will be masked. Acceptable values are "h" (horizontal only), "v" (vertical @@ -50,8 +51,8 @@ #'@param debug Bool, Defaults to \code{FALSE}. Set to \code{TRUE} to show #' rectangles around all \code{geom_rect()} elements for debugging. #'@param overrides Named list, overrides the default drawing attributes defined -#' in \code{cmapplot_globals$consts} which are drawn by \code{\link{theme_cmap}}. -#' Units are in bigpts (1/72 of an inch). +#' in \code{cmapplot_globals$consts} which are drawn by +#' \code{\link{theme_cmap}}. Units are in bigpts (1/72 of an inch). #'@param ... pass additional arguments to ggplot2's \code{\link[ggplot2]{theme}} #' function to override any elements of the default CMAP theme. #' From 7060aa5aff3535f6d11714c0e82214d82ac87415 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 00:08:05 -0500 Subject: [PATCH 04/83] implement envir getter and setter basic, for testing. would need documentation if it works. --- R/cmapplot.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/cmapplot.R b/R/cmapplot.R index 0d693809..a740d980 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -107,6 +107,22 @@ cmapplot_globals$consts = list( } +get_cmapplot_global <- function(name){ + get(name, envir = cmapplot_globals) +} + +set_cmapplot_global <- function(name, value){ + + # do a get to make sure the variable exists. + p <- get_cmapplot_global(name) + + assign(name, value, envir = cmapplot_globals) + + invisible() +} + + + # Font spec visualization helper function --------------------------------- #' Font visualization test From 874bff3330bec59db9c2b65b935db93a1f299977 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 00:13:55 -0500 Subject: [PATCH 05/83] documentation --- NAMESPACE | 5 ++++- R/cmapplot.R | 2 ++ ...pplot_globals.Rd => cmapplot_globals_OLD.Rd} | 8 ++++---- man/theme_cmap.Rd | 17 +++++++++-------- 4 files changed, 19 insertions(+), 13 deletions(-) rename man/{cmapplot_globals.Rd => cmapplot_globals_OLD.Rd} (96%) diff --git a/NAMESPACE b/NAMESPACE index 9494d632..4e6bfde2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,12 +20,14 @@ export(cmap_fill_highlight) export(cmap_fill_race) export(cmap_gradients) export(cmap_palettes) -export(cmapplot_globals) +export(cmapplot_globals_OLD) export(finalize_plot) export(geom_recessions) export(geom_text_lastonly) +export(get_cmapplot_global) export(gg_lwd_convert) export(integer_breaks) +export(set_cmapplot_global) export(theme_cmap) export(unapply_cmap_default_aes) export(update_recessions) @@ -39,6 +41,7 @@ import(grid) import(gridtext) import(rlang) import(scales) +import(systemfonts) importFrom(generics,intersect) importFrom(ggpubr,get_legend) importFrom(glue,glue) diff --git a/R/cmapplot.R b/R/cmapplot.R index a740d980..030df660 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -107,10 +107,12 @@ cmapplot_globals$consts = list( } +#' @export get_cmapplot_global <- function(name){ get(name, envir = cmapplot_globals) } +#' @export set_cmapplot_global <- function(name, value){ # do a get to make sure the variable exists. diff --git a/man/cmapplot_globals.Rd b/man/cmapplot_globals_OLD.Rd similarity index 96% rename from man/cmapplot_globals.Rd rename to man/cmapplot_globals_OLD.Rd index df2e9ac7..97ccaf96 100644 --- a/man/cmapplot_globals.Rd +++ b/man/cmapplot_globals_OLD.Rd @@ -1,14 +1,14 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/cmapplot.R \docType{data} -\name{cmapplot_globals} -\alias{cmapplot_globals} +\name{cmapplot_globals_OLD} +\alias{cmapplot_globals_OLD} \title{cmapplot global variables} \format{ -An object of class \code{list} of length 8. +An object of class \code{list} of length 0. } \usage{ -cmapplot_globals +cmapplot_globals_OLD } \description{ A list of predefined variables for use by the cmapplot package and its users. diff --git a/man/theme_cmap.Rd b/man/theme_cmap.Rd index 0d6e1ad4..8985c070 100644 --- a/man/theme_cmap.Rd +++ b/man/theme_cmap.Rd @@ -27,10 +27,11 @@ details for unexpected outcomes when using these arguments along with \item{hline, vline}{Numeric, the location of a strong horizontal or vertical line to be added to the plot. Use \code{hline = 0}, for example, to place a -line at y = 0 to differentiate between positive and negative values. The width -of this line is determined by \code{cmapplot_globals$lwd_strongline}. Note that -on most displays the difference between this line and gridlines is impossible -to discern in R. The difference will be visible upon export.} +line at y = 0 to differentiate between positive and negative values. The +width of this line is determined by +\code{cmapplot_globals$consts$lwd_strongline}. Note that on most displays +the difference between this line and gridlines is impossible to discern in +R. The difference will be visible upon export.} \item{gridlines}{Char, the grid lines to be displayed on the chart. If left as default, horizontal grid lines will be displayed while vertical grid lines @@ -64,8 +65,8 @@ be one row of three and another row of two).} rectangles around all \code{geom_rect()} elements for debugging.} \item{overrides}{Named list, overrides the default drawing attributes defined -in \code{cmapplot_globals$consts} which are drawn by \code{\link{theme_cmap}}. -Units are in bigpts (1/72 of an inch).} +in \code{cmapplot_globals$consts} which are drawn by +\code{\link{theme_cmap}}. Units are in bigpts (1/72 of an inch).} \item{...}{pass additional arguments to ggplot2's \code{\link[ggplot2]{theme}} function to override any elements of the default CMAP theme.} @@ -79,8 +80,8 @@ Using either the \code{xlab} or \code{ylab} argument, but not both, will have undesireable outcomes in a ggplot that also invokes \code{coord_flip()}. Under the hood, \code{theme_cmap(xlab = "foo")} both sets \code{ggplot2::xlab = "foo"} and 'turns on' the ggplot theme element \code{axis.title.x}. With -\code{coord_flip()}, the xlab travels with the data (becoming the ylab) but the -theme modifier stays on the x axis. To solve this, rewrite your ggplot +\code{coord_flip()}, the xlab travels with the data (becoming the ylab) but +the theme modifier stays on the x axis. To solve this, rewrite your ggplot construction to avoid \code{coord_flip()} or manually turn off and on the correct elements from ggplot2's \code{\link[ggplot2]{theme}} function in the \code{...} of this function. From 0f7bb584580975169895fd486e35c5338da7357a Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 00:26:51 -0500 Subject: [PATCH 06/83] left some notes not sure why exporting doesn't seem to be working --- R/cmapplot.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/cmapplot.R b/R/cmapplot.R index 030df660..d8ee21ba 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -107,6 +107,9 @@ cmapplot_globals$consts = list( } +# why aren't these available functions? +# and, I'd like to figure out how to parse for $ + #' @export get_cmapplot_global <- function(name){ get(name, envir = cmapplot_globals) From 1de5255531e954bc0d97a092f133baad61d41856 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 00:43:07 -0500 Subject: [PATCH 07/83] more fiddling --- DESCRIPTION | 2 +- NAMESPACE | 1 - R/cmapplot.R | 6 +++++- man/get_cmapplot_global.Rd | 11 +++++++++++ man/set_cmapplot_global.Rd | 11 +++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 man/get_cmapplot_global.Rd create mode 100644 man/set_cmapplot_global.Rd diff --git a/DESCRIPTION b/DESCRIPTION index d9b92bf0..1e6e1291 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -51,7 +51,7 @@ Imports: rlang, scales, stringr, - sysfonts + systemfonts Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 4e6bfde2..604cd7f9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -53,6 +53,5 @@ importFrom(purrr,map) importFrom(purrr,walk2) importFrom(stringr,str_replace) importFrom(stringr,str_trunc) -importFrom(sysfonts,font_files) importFrom(utils,modifyList) importFrom(utils,read.csv) diff --git a/R/cmapplot.R b/R/cmapplot.R index d8ee21ba..1be57f1c 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -13,7 +13,6 @@ #' @docType package #' @import ggplot2 dplyr grid scales grDevices graphics rlang gridtext #' @importFrom glue glue glue_collapse -#' @importFrom sysfonts font_files #' @keywords internal "_PACKAGE" @@ -110,11 +109,16 @@ cmapplot_globals$consts = list( # why aren't these available functions? # and, I'd like to figure out how to parse for $ +#' Get a value from the cmapplot_globals environment +#' #' @export get_cmapplot_global <- function(name){ get(name, envir = cmapplot_globals) } + +#' Set a value in the cmapplot_globals environment +#' #' @export set_cmapplot_global <- function(name, value){ diff --git a/man/get_cmapplot_global.Rd b/man/get_cmapplot_global.Rd new file mode 100644 index 00000000..1774974c --- /dev/null +++ b/man/get_cmapplot_global.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cmapplot.R +\name{get_cmapplot_global} +\alias{get_cmapplot_global} +\title{Get a value from the cmapplot_globals environment} +\usage{ +get_cmapplot_global(name) +} +\description{ +Get a value from the cmapplot_globals environment +} diff --git a/man/set_cmapplot_global.Rd b/man/set_cmapplot_global.Rd new file mode 100644 index 00000000..986698b2 --- /dev/null +++ b/man/set_cmapplot_global.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cmapplot.R +\name{set_cmapplot_global} +\alias{set_cmapplot_global} +\title{Set a value in the cmapplot_globals environment} +\usage{ +set_cmapplot_global(name, value) +} +\description{ +Set a value in the cmapplot_globals environment +} From 02c10211487a226764ae82338bff9df18fe2ce21 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 00:57:55 -0500 Subject: [PATCH 08/83] working now, check passes --- R/cmapplot.R | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 1be57f1c..78a96a82 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -69,6 +69,8 @@ cmapplot_globals$consts = list( #' @import systemfonts .onLoad <- function(...) { + family <- name <- path <- NULL + # check for Whitney all_fonts <- systemfonts::system_fonts() whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] @@ -97,23 +99,28 @@ cmapplot_globals$consts = list( # Load CMAP preferred default.aes (can't be done until fonts are specified) assign("default_aes_cmap", init_cmap_default_aes(), - env = cmapplot_globals) + envir = cmapplot_globals) # Cache existing default.aes assign("default_aes_cached", fetch_current_default_aes(), - env = cmapplot_globals) + envir = cmapplot_globals) } -# why aren't these available functions? -# and, I'd like to figure out how to parse for $ +# Figure out how to parse for $ #' Get a value from the cmapplot_globals environment #' #' @export get_cmapplot_global <- function(name){ + + # WORKING HERE + #names <- stringr::str_split(name, "\\$")[[1]] + #top <- get(names[[1]], envir = cmapplot_globals) + get(name, envir = cmapplot_globals) + } From 21d0bec96a63b71d70966239827b8b8e5b02894d Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 12:03:05 -0500 Subject: [PATCH 09/83] working get and set --- R/cmapplot.R | 55 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 78a96a82..fd2bb93d 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -113,13 +113,24 @@ cmapplot_globals$consts = list( #' Get a value from the cmapplot_globals environment #' #' @export -get_cmapplot_global <- function(name){ +get_cmapplot_global <- function(...){ - # WORKING HERE - #names <- stringr::str_split(name, "\\$")[[1]] - #top <- get(names[[1]], envir = cmapplot_globals) + # establish vector of sublocations + names <- unlist(stringr::str_split(c(...), "\\$")) - get(name, envir = cmapplot_globals) + # fetch the top-level element from the list + var <- get(names[1], envir = cmapplot_globals) + + # recurse over additional names to extract the right value + for(i in seq_along(names[-1])+1){ + var <- var[[names[i]]] + } + + if(is.null(var)){ + stop(paste0("object '", paste(names, collapse = "$"), "' not found")) + } + + return(var) } @@ -127,12 +138,38 @@ get_cmapplot_global <- function(name){ #' Set a value in the cmapplot_globals environment #' #' @export -set_cmapplot_global <- function(name, value){ +set_cmapplot_global <- function(value, ..., quietly = FALSE){ + + # do a full get to make sure the variable exists. + # this is a throw-away, just used to as a check + p <- get_cmapplot_global(...) - # do a get to make sure the variable exists. - p <- get_cmapplot_global(name) + # establish vector of sublocations + names <- unlist(stringr::str_split(c(...), "\\$")) - assign(name, value, envir = cmapplot_globals) + # get the top-level item + item <- get_cmapplot_global(names[1]) + + # build a string to evaluate that modifies some element of the item. + str <- paste0( + "item", + ifelse(length(names)>1, paste0("$", paste(names[-1], collapse = "$")),""), + "<- '", value, "'") + + # replace the specific item by evaluating the string + eval(parse(text = str)) + + # and replace the top level item in the globals env + assign(names[1], item, envir = cmapplot_globals) + + # report + if(!quietly){ + cat(paste0( + "Item: ", paste(names, collapse = "$"), "\n", + "Old value: '", p, "'\n", + "New value: '", value, "'" + )) + } invisible() } From af920efe0ee85d6433e2125f67002dc54abbbbe3 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 12:16:52 -0500 Subject: [PATCH 10/83] mas --- R/cmapplot.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index fd2bb93d..cac3b547 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -107,11 +107,17 @@ cmapplot_globals$consts = list( envir = cmapplot_globals) } - -# Figure out how to parse for $ +#' Get all values from the cmapplot_globals environment +#' +#' @export +get_cmapplot_globals <- function(){ + as.list(cmapplot_globals) +} #' Get a value from the cmapplot_globals environment #' +#' @describeIn get_cmapplot_globals +#' #' @export get_cmapplot_global <- function(...){ @@ -137,6 +143,7 @@ get_cmapplot_global <- function(...){ #' Set a value in the cmapplot_globals environment #' +#' @describeIn get_cmapplot_globals #' @export set_cmapplot_global <- function(value, ..., quietly = FALSE){ From b906067260957d412d3e69872f26c67b2119496a Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 3 Apr 2021 12:28:40 -0500 Subject: [PATCH 11/83] documentation --- NAMESPACE | 2 +- R/cmapplot.R | 115 +++++++++--------- man/get_cmapplot_global.Rd | 11 -- ...globals_OLD.Rd => get_cmapplot_globals.Rd} | 30 +++-- man/set_cmapplot_global.Rd | 11 -- 5 files changed, 79 insertions(+), 90 deletions(-) delete mode 100644 man/get_cmapplot_global.Rd rename man/{cmapplot_globals_OLD.Rd => get_cmapplot_globals.Rd} (87%) delete mode 100644 man/set_cmapplot_global.Rd diff --git a/NAMESPACE b/NAMESPACE index 604cd7f9..127c7c61 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,11 +20,11 @@ export(cmap_fill_highlight) export(cmap_fill_race) export(cmap_gradients) export(cmap_palettes) -export(cmapplot_globals_OLD) export(finalize_plot) export(geom_recessions) export(geom_text_lastonly) export(get_cmapplot_global) +export(get_cmapplot_globals) export(gg_lwd_convert) export(integer_breaks) export(set_cmapplot_global) diff --git a/R/cmapplot.R b/R/cmapplot.R index cac3b547..d55071c2 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -107,16 +107,69 @@ cmapplot_globals$consts = list( envir = cmapplot_globals) } -#' Get all values from the cmapplot_globals environment +#'The cmapplot_globals environment #' -#' @export +#'The \code{cmapplot_globals} environment contains a list of predefined +#'variables for use by the cmapplot package and its users. It includes commonly +#'used colors, font and font size specifications, and a list of constants which +#'aid in drawing cmap-themed plots. +#' +#'@section Plot Constants: The primary portion of these global variables of +#' interest to the user is \code{cmapplot_globals$consts}, a list of default +#' constants that set certain plot aesthetics. Units of all plot constants are +#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be +#' overridden) in \code{\link{finalize_plot}}: these are marked below with an +#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: +#' these are marked with \strong{T}. +#' +#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn +#' vertically or horizontally with the \code{hline, vline} args of +#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This +#' thinner-width line is drawn vertically or horizontally with the +#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item +#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. +#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. +#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but +#' not overridable in either context. (Modify by setting the size explicitly in +#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: +#' The width of the line above the plot. \strong{(F)} \item +#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} +#' \item \code{margin_topline_t}: The margin between the top edge of the image +#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin +#' between the top line and the title. \strong{(F)} \item +#' \code{margin_title_b}: The margin between the title and the caption when +#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: +#' The margin between the bottom of the caption and the bottom edge of the +#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top +#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item +#' \code{margin_legend_i}: The margin between legends (this only applies in +#' plots with two or more legends and does not affect legend spacing on plots +#' with single legends that have multiple rows). \strong{(T, F)} \item +#' \code{margin_legend_b}: The margin between the bottom of the legend and the +#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin +#' between the bottom of the plot and the bottom edge of the image (or top of +#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the +#' left edge of the image and the title and caption, when the sidebar exists. +#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: +#' The margin between the left edge of the plot and the sodebar. \strong{(F)} +#' \item \code{margin_plot_r}: The margin between the right edge of the plot +#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding +#' between the plot and its right-hand drawing extent. Override this based on +#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: +#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text +#' leading for Caption text. \strong{(F)} } +#' +#'@describeIn get_cmapplot_globals Get the entire environment as a list. +#' +#'@export get_cmapplot_globals <- function(){ as.list(cmapplot_globals) } #' Get a value from the cmapplot_globals environment #' -#' @describeIn get_cmapplot_globals +#' +#' @describeIn get_cmapplot_globals Get a specific global value #' #' @export get_cmapplot_global <- function(...){ @@ -143,7 +196,7 @@ get_cmapplot_global <- function(...){ #' Set a value in the cmapplot_globals environment #' -#' @describeIn get_cmapplot_globals +#' @describeIn get_cmapplot_globals Set a specific global value #' @export set_cmapplot_global <- function(value, ..., quietly = FALSE){ @@ -285,57 +338,3 @@ gg_lwd_convert <- function(value, unit = "bigpts") { ) } - -#'cmapplot global variables -#' -#'A list of predefined variables for use by the cmapplot package and its users. -#'It includes commonly used colors, font and font size specifications, and a -#'list of constants which aid in drawing cmap-themed plots. -#' -#'@section Plot Constants: The only portion of these global variables of -#' interest to the user is \code{cmapplot_globals$consts}, a list of default -#' constants that set certain plot aesthetics. Units of all plot constants are -#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be -#' overridden) in \code{\link{finalize_plot}}: these are marked below with an -#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: -#' these are marked with \strong{T}. -#' -#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn -#' vertically or horizontally with the \code{hline, vline} args of -#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This -#' thinner-width line is drawn vertically or horizontally with the -#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item -#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. -#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. -#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but -#' not overridable in either context. (Modify by setting the size explicitly in -#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: -#' The width of the line above the plot. \strong{(F)} \item -#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} -#' \item \code{margin_topline_t}: The margin between the top edge of the image -#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin -#' between the top line and the title. \strong{(F)} \item -#' \code{margin_title_b}: The margin between the title and the caption when -#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: -#' The margin between the bottom of the caption and the bottom edge of the -#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top -#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item -#' \code{margin_legend_i}: The margin between legends (this only applies in -#' plots with two or more legends and does not affect legend spacing on plots -#' with single legends that have multiple rows). \strong{(T, F)} \item -#' \code{margin_legend_b}: The margin between the bottom of the legend and the -#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin -#' between the bottom of the plot and the bottom edge of the image (or top of -#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the -#' left edge of the image and the title and caption, when the sidebar exists. -#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: -#' The margin between the left edge of the plot and the sodebar. \strong{(F)} -#' \item \code{margin_plot_r}: The margin between the right edge of the plot -#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding -#' between the plot and its right-hand drawing extent. Override this based on -#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: -#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text -#' leading for Caption text. \strong{(F)} } -#' -#'@export -cmapplot_globals_OLD <- list() diff --git a/man/get_cmapplot_global.Rd b/man/get_cmapplot_global.Rd deleted file mode 100644 index 1774974c..00000000 --- a/man/get_cmapplot_global.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cmapplot.R -\name{get_cmapplot_global} -\alias{get_cmapplot_global} -\title{Get a value from the cmapplot_globals environment} -\usage{ -get_cmapplot_global(name) -} -\description{ -Get a value from the cmapplot_globals environment -} diff --git a/man/cmapplot_globals_OLD.Rd b/man/get_cmapplot_globals.Rd similarity index 87% rename from man/cmapplot_globals_OLD.Rd rename to man/get_cmapplot_globals.Rd index 97ccaf96..2a42a954 100644 --- a/man/cmapplot_globals_OLD.Rd +++ b/man/get_cmapplot_globals.Rd @@ -1,20 +1,33 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/cmapplot.R -\docType{data} -\name{cmapplot_globals_OLD} -\alias{cmapplot_globals_OLD} -\title{cmapplot global variables} -\format{ -An object of class \code{list} of length 0. -} +\name{get_cmapplot_globals} +\alias{get_cmapplot_globals} +\alias{get_cmapplot_global} +\alias{set_cmapplot_global} +\title{The cmapplot_globals environment} \usage{ -cmapplot_globals_OLD +get_cmapplot_globals() + +get_cmapplot_global(...) + +set_cmapplot_global(value, ..., quietly = FALSE) } \description{ A list of predefined variables for use by the cmapplot package and its users. It includes commonly used colors, font and font size specifications, and a list of constants which aid in drawing cmap-themed plots. + +This sets. } +\section{Functions}{ +\itemize{ +\item \code{get_cmapplot_globals}: Get the entire environment as a list. + +\item \code{get_cmapplot_global}: Get a specific global value + +\item \code{set_cmapplot_global}: Set a specific global value +}} + \section{Plot Constants}{ The only portion of these global variables of interest to the user is \code{cmapplot_globals$consts}, a list of default @@ -62,4 +75,3 @@ list of constants which aid in drawing cmap-themed plots. leading for Caption text. \strong{(F)} } } -\keyword{datasets} diff --git a/man/set_cmapplot_global.Rd b/man/set_cmapplot_global.Rd deleted file mode 100644 index 986698b2..00000000 --- a/man/set_cmapplot_global.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cmapplot.R -\name{set_cmapplot_global} -\alias{set_cmapplot_global} -\title{Set a value in the cmapplot_globals environment} -\usage{ -set_cmapplot_global(name, value) -} -\description{ -Set a value in the cmapplot_globals environment -} From 680c7cada8b516bb6cc496f67bcf0d6b5fa1095f Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 4 Apr 2021 22:43:50 -0500 Subject: [PATCH 12/83] final changes? I hope --- R/cmapplot.R | 176 +------------------------------- R/cmapplot_globals.R | 196 ++++++++++++++++++++++++++++++++++++ man/get_cmapplot_globals.Rd | 37 +++++-- pkgdown/_pkgdown.yml | 2 +- vignettes/colors.Rmd | 3 +- vignettes/cookbook.Rmd | 3 +- vignettes/finalize.Rmd | 3 +- vignettes/installation.Rmd | 4 +- vignettes/plots.Rmd | 3 +- 9 files changed, 242 insertions(+), 185 deletions(-) create mode 100644 R/cmapplot_globals.R diff --git a/R/cmapplot.R b/R/cmapplot.R index d55071c2..490a25c7 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -18,51 +18,6 @@ -# establish location for cmapplot global variables -cmapplot_globals <- new.env(parent = emptyenv()) - -# set up default font handling -# (overridden if local machine has Whitney in .onLoad) -cmapplot_globals$use_whitney <- FALSE -cmapplot_globals$font <- list( - strong = list(family = "sans", face = "bold"), - regular = list(family = "sans", face = "plain"), - light = list(family = "sans", face = "plain")) - -# establish font sizes -cmapplot_globals$fsize <- list( - S = 11, - M = 14, - L = 17 -) - -## Colors -cmapplot_globals$colors <- list( - blackish = "#222222" - ) - -## Establish plotting constants in bigpts (1/72 of inch) -cmapplot_globals$consts = list( - lwd_gridline = 0.3, - lwd_strongline = 1, - lwd_plotline = 3, - lwd_topline = 2, - length_ticks = 7, - margin_topline_t = 5, - margin_title_t = 5, - margin_title_b = 5, - margin_caption_b = 5, - margin_legend_t = 5, - margin_legend_i = 8, - margin_legend_b = 10, - margin_plot_b = 5, - margin_sidebar_l = 2, - margin_plot_l = 10, - margin_plot_r = 10, - margin_panel_r = 10, - leading_title = 1, - leading_caption = 1 - ) ## Update fonts based on system -- *must* be done with .onLoad() @@ -90,10 +45,6 @@ cmapplot_globals$consts = list( regular = list(family = "Whitney-Medium", face = "plain"), light = list(family = "Whitney-Book", face = "plain")), envir = cmapplot_globals) - } else { - packageStartupMessage( - "WARNING: Whitney is not installed on this machine, so CMAP theme will use your default sans-Serif font" - ) } # Load CMAP preferred default.aes (can't be done until fonts are specified) @@ -107,133 +58,16 @@ cmapplot_globals$consts = list( envir = cmapplot_globals) } -#'The cmapplot_globals environment -#' -#'The \code{cmapplot_globals} environment contains a list of predefined -#'variables for use by the cmapplot package and its users. It includes commonly -#'used colors, font and font size specifications, and a list of constants which -#'aid in drawing cmap-themed plots. -#' -#'@section Plot Constants: The primary portion of these global variables of -#' interest to the user is \code{cmapplot_globals$consts}, a list of default -#' constants that set certain plot aesthetics. Units of all plot constants are -#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be -#' overridden) in \code{\link{finalize_plot}}: these are marked below with an -#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: -#' these are marked with \strong{T}. -#' -#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn -#' vertically or horizontally with the \code{hline, vline} args of -#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This -#' thinner-width line is drawn vertically or horizontally with the -#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item -#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. -#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. -#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but -#' not overridable in either context. (Modify by setting the size explicitly in -#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: -#' The width of the line above the plot. \strong{(F)} \item -#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} -#' \item \code{margin_topline_t}: The margin between the top edge of the image -#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin -#' between the top line and the title. \strong{(F)} \item -#' \code{margin_title_b}: The margin between the title and the caption when -#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: -#' The margin between the bottom of the caption and the bottom edge of the -#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top -#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item -#' \code{margin_legend_i}: The margin between legends (this only applies in -#' plots with two or more legends and does not affect legend spacing on plots -#' with single legends that have multiple rows). \strong{(T, F)} \item -#' \code{margin_legend_b}: The margin between the bottom of the legend and the -#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin -#' between the bottom of the plot and the bottom edge of the image (or top of -#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the -#' left edge of the image and the title and caption, when the sidebar exists. -#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: -#' The margin between the left edge of the plot and the sodebar. \strong{(F)} -#' \item \code{margin_plot_r}: The margin between the right edge of the plot -#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding -#' between the plot and its right-hand drawing extent. Override this based on -#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: -#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text -#' leading for Caption text. \strong{(F)} } -#' -#'@describeIn get_cmapplot_globals Get the entire environment as a list. -#' -#'@export -get_cmapplot_globals <- function(){ - as.list(cmapplot_globals) -} - -#' Get a value from the cmapplot_globals environment -#' -#' -#' @describeIn get_cmapplot_globals Get a specific global value -#' -#' @export -get_cmapplot_global <- function(...){ - - # establish vector of sublocations - names <- unlist(stringr::str_split(c(...), "\\$")) - # fetch the top-level element from the list - var <- get(names[1], envir = cmapplot_globals) - - # recurse over additional names to extract the right value - for(i in seq_along(names[-1])+1){ - var <- var[[names[i]]] - } - - if(is.null(var)){ - stop(paste0("object '", paste(names, collapse = "$"), "' not found")) +.onAttach <- function(...){ + if(!get("use_whitney", envir = cmapplot_globals)){ + packageStartupMessage( + "WARNING: Whitney is not installed on this machine, so CMAP theme will use your default sans-Serif font" + ) } - - return(var) - } -#' Set a value in the cmapplot_globals environment -#' -#' @describeIn get_cmapplot_globals Set a specific global value -#' @export -set_cmapplot_global <- function(value, ..., quietly = FALSE){ - - # do a full get to make sure the variable exists. - # this is a throw-away, just used to as a check - p <- get_cmapplot_global(...) - - # establish vector of sublocations - names <- unlist(stringr::str_split(c(...), "\\$")) - - # get the top-level item - item <- get_cmapplot_global(names[1]) - - # build a string to evaluate that modifies some element of the item. - str <- paste0( - "item", - ifelse(length(names)>1, paste0("$", paste(names[-1], collapse = "$")),""), - "<- '", value, "'") - - # replace the specific item by evaluating the string - eval(parse(text = str)) - - # and replace the top level item in the globals env - assign(names[1], item, envir = cmapplot_globals) - - # report - if(!quietly){ - cat(paste0( - "Item: ", paste(names, collapse = "$"), "\n", - "Old value: '", p, "'\n", - "New value: '", value, "'" - )) - } - - invisible() -} - # Font spec visualization helper function --------------------------------- diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R new file mode 100644 index 00000000..8eb7e2b9 --- /dev/null +++ b/R/cmapplot_globals.R @@ -0,0 +1,196 @@ +# establish location for cmapplot global variables +cmapplot_globals <- new.env(parent = emptyenv()) + +# set up default font handling +# (overridden if local machine has Whitney in .onLoad) +cmapplot_globals$use_whitney <- FALSE +cmapplot_globals$font <- list( + strong = list(family = "sans", face = "bold"), + regular = list(family = "sans", face = "plain"), + light = list(family = "sans", face = "plain")) + +# establish font sizes +cmapplot_globals$fsize <- list( + S = 11, + M = 14, + L = 17 +) + +## Colors +cmapplot_globals$colors <- list( + blackish = "#222222" +) + +## Establish plotting constants in bigpts (1/72 of inch) +cmapplot_globals$consts <- list( + lwd_gridline = 0.3, + lwd_strongline = 1, + lwd_plotline = 3, + lwd_topline = 2, + length_ticks = 7, + margin_topline_t = 5, + margin_title_t = 5, + margin_title_b = 5, + margin_caption_b = 5, + margin_legend_t = 5, + margin_legend_i = 8, + margin_legend_b = 10, + margin_plot_b = 5, + margin_sidebar_l = 2, + margin_plot_l = 10, + margin_plot_r = 10, + margin_panel_r = 10, + leading_title = 1, + leading_caption = 1 +) + +#'The cmapplot_globals environment +#' +#'The \code{cmapplot_globals} environment contains a list of predefined +#'variables for use by the cmapplot package and its users. It includes commonly +#'used colors, font and font size specifications, and a list of constants which +#'aid in drawing cmap-themed plots. It cannot be accessed directly, but the +#'helper functions described here provide the user access if needed. +#' +#'@section Plot Constants: The primary portion of these global variables of +#' interest to the user is \code{cmapplot_globals$consts}, a list of default +#' constants that set certain plot aesthetics. Units of all plot constants are +#' "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be +#' overridden) in \code{\link{finalize_plot}}: these are marked below with an +#' \strong{F}. Some are used/can be overridden in \code{\link{theme_cmap}}: +#' these are marked with \strong{T}. +#' +#' \itemize{ \item \code{lwd_strongline}: This stronger-width line is drawn +#' vertically or horizontally with the \code{hline, vline} args of +#' \code{theme_cmap()}. \strong{(T)} \item \code{lwd_gridline}: This +#' thinner-width line is drawn vertically or horizontally with the +#' \code{gridlines, axislines} args of \code{theme_cmap()}. \strong{(T)} \item +#' \code{lwd_plotline}: The width of any lines drawn by geoms in the plot (e.g. +#' \code{geom_line}) but not explicitly sized by the geom's aesthetic. +#' Implemented by \code{finalize_plot} or by \code{apply_cmap_default_aes} but +#' not overridable in either context. (Modify by setting the size explicitly in +#' the geom, but see \code{gg_lwd_convert} first.) \item \code{lwd_topline}: +#' The width of the line above the plot. \strong{(F)} \item +#' \code{length_ticks}: The length of the axis ticks (if shown). \strong{(T)} +#' \item \code{margin_topline_t}: The margin between the top edge of the image +#' and the top line. \strong{(F)} \item \code{margin_title_t}: The margin +#' between the top line and the title. \strong{(F)} \item +#' \code{margin_title_b}: The margin between the title and the caption when +#' both are drawn in the sidebar. \strong{(F)} \item \code{margin_caption_b}: +#' The margin between the bottom of the caption and the bottom edge of the +#' image. \strong{(F)} \item \code{margin_legend_t}: The margin between the top +#' line and the plot box (i.e., the top of the legend). \strong{(F)} \item +#' \code{margin_legend_i}: The margin between legends (this only applies in +#' plots with two or more legends and does not affect legend spacing on plots +#' with single legends that have multiple rows). \strong{(T, F)} \item +#' \code{margin_legend_b}: The margin between the bottom of the legend and the +#' rest of the plot. \strong{(T, F)} \item \code{margin_plot_b}: The margin +#' between the bottom of the plot and the bottom edge of the image (or top of +#' caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the +#' left edge of the image and the title and caption, when the sidebar exists. +#' Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: +#' The margin between the left edge of the plot and the sodebar. \strong{(F)} +#' \item \code{margin_plot_r}: The margin between the right edge of the plot +#' and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding +#' between the plot and its right-hand drawing extent. Override this based on +#' space needed for x axis labels. \strong{(T)} \item \code{leading_title}: +#' Text leading for Title text. \strong{(F)} \item \code{leading_caption}: Text +#' leading for Caption text. \strong{(F)} } +#' +#' @aliases cmapplot_globals +#' +#' @describeIn get_cmapplot_globals Get the entire environment as a list. +#' +#' @export +get_cmapplot_globals <- function(){ + as.list(cmapplot_globals) +} + +#' Get a value from the cmapplot_globals environment +#' +#' @examples +#' +#' # These are the same: +#' get_cmapplot_global("consts$lwd_gridline") +#' get_cmapplot_global("consts", "lwd_gridline") +#' +#' @describeIn get_cmapplot_globals Get a specific global value +#' +#' @export +get_cmapplot_global <- function(...){ + + # establish vector of sublocations + names <- unlist(stringr::str_split(c(...), "\\$")) + + # fetch the top-level element from the list + var <- get(names[1], envir = cmapplot_globals) + + # recurse over additional names to extract the right value + for(i in seq_along(names[-1])+1){ + var <- var[[names[i]]] + } + + if(is.null(var)){ + stop(paste0("object '", paste(names, collapse = "$"), "' not found")) + } + + return(var) + +} + + +#' Set a value in the cmapplot_globals environment +#' +#' @param value the value to be set +#' +#' @param ... The path to the variable within \code{cmapplot_globals} to be +#' get/set. The function willparse \code{$}, or recursive list elements can be +#' split over multiple arguments (e.g. \code{"font$strong$family"} is +#' equivalent to \code{"font", "strong", "family"}). +#' +#' @param quietly suppress confirmatory messages +#' +#' @examples +#' +#' # Globals can be modified if needed +#' set_cmapplot_global(5, "consts$lwd_gridline") +#' get_cmapplot_global("consts$lwd_gridline") +#' +#' @describeIn get_cmapplot_globals Set a specific global value +#' +#' @export +set_cmapplot_global <- function(value, ..., quietly = FALSE){ + + # do a full get to make sure the variable exists. + # this is a throw-away, just used to as a check + p <- get_cmapplot_global(...) + + # establish vector of sublocations + names <- unlist(stringr::str_split(c(...), "\\$")) + + # get the top-level item + item <- get_cmapplot_global(names[1]) + + # build a string to evaluate that modifies some element of the item. + str <- paste0( + "item", + ifelse(length(names)>1, paste0("$", paste(names[-1], collapse = "$")),""), + "<- '", value, "'") + + # replace the specific item by evaluating the string + eval(parse(text = str)) + + # and replace the top level item in the globals env + assign(names[1], item, envir = cmapplot_globals) + + # report + if(!quietly){ + cat(paste0( + "Item: ", paste(names, collapse = "$"), "\n", + "Old value: '", p, "'\n", + "New value: '", value, "'" + )) + } + + invisible() +} diff --git a/man/get_cmapplot_globals.Rd b/man/get_cmapplot_globals.Rd index 2a42a954..e39f8f93 100644 --- a/man/get_cmapplot_globals.Rd +++ b/man/get_cmapplot_globals.Rd @@ -1,7 +1,8 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cmapplot.R +% Please edit documentation in R/cmapplot_globals.R \name{get_cmapplot_globals} \alias{get_cmapplot_globals} +\alias{cmapplot_globals} \alias{get_cmapplot_global} \alias{set_cmapplot_global} \title{The cmapplot_globals environment} @@ -12,12 +13,22 @@ get_cmapplot_global(...) set_cmapplot_global(value, ..., quietly = FALSE) } -\description{ -A list of predefined variables for use by the cmapplot package and its users. -It includes commonly used colors, font and font size specifications, and a -list of constants which aid in drawing cmap-themed plots. +\arguments{ +\item{...}{The path to the variable within \code{cmapplot_globals} to be +get/set. The function willparse \code{$}, or recursive list elements can be +split over multiple arguments (e.g. \code{"font$strong$family"} is +equivalent to \code{"font", "strong", "family"}).} + +\item{value}{the value to be set} -This sets. +\item{quietly}{suppress confirmatory messages} +} +\description{ +The \code{cmapplot_globals} environment contains a list of predefined +variables for use by the cmapplot package and its users. It includes commonly +used colors, font and font size specifications, and a list of constants which +aid in drawing cmap-themed plots. It cannot be accessed directly, but the +helper functions described here provide the user access if needed. } \section{Functions}{ \itemize{ @@ -29,7 +40,7 @@ This sets. }} \section{Plot Constants}{ - The only portion of these global variables of + The primary portion of these global variables of interest to the user is \code{cmapplot_globals$consts}, a list of default constants that set certain plot aesthetics. Units of all plot constants are "bigpts": 1/72 of an inch. Most plot constants are invoked (and can be @@ -75,3 +86,15 @@ This sets. leading for Caption text. \strong{(F)} } } +\examples{ + +# These are the same: +get_cmapplot_global("consts$lwd_gridline") +get_cmapplot_global("consts", "lwd_gridline") + + +# Globals can be modified if needed +set_cmapplot_global(5, "consts$lwd_gridline") +get_cmapplot_global("consts$lwd_gridline") + +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 19d5dae9..0829b77a 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -41,7 +41,7 @@ reference: - vehicle_ownership - title: Lesser used objects - contents: - - cmapplot_globals + - ends_with("cmapplot_globals") - gg_lwd_convert - update_recessions - customproto diff --git a/vignettes/colors.Rmd b/vignettes/colors.Rmd index f5ed7cad..945b924e 100644 --- a/vignettes/colors.Rmd +++ b/vignettes/colors.Rmd @@ -14,7 +14,8 @@ knitr::opts_chunk$set( fig.width = 7, fig.asp = 400/670, fig.retina = 4, - fig.align = "center" + fig.align = "center", + dev = "ragg_png" ) library(tidyverse) diff --git a/vignettes/cookbook.Rmd b/vignettes/cookbook.Rmd index d3f16052..b3d3b319 100644 --- a/vignettes/cookbook.Rmd +++ b/vignettes/cookbook.Rmd @@ -15,7 +15,8 @@ knitr::opts_chunk$set( fig.asp = 400/670, fig.retina = 4, fig.align = "center", - out.width = "100%" + out.width = "100%", + dev = "ragg_png" ) library(tidyverse) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 44cb9910..84520827 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -15,7 +15,8 @@ knitr::opts_chunk$set( fig.asp = 400/670, fig.retina = 4, fig.align = "center", - out.width = "100%" + out.width = "100%", + dev = "ragg_png" ) library(tidyverse) diff --git a/vignettes/installation.Rmd b/vignettes/installation.Rmd index ed3a5224..43f23f09 100644 --- a/vignettes/installation.Rmd +++ b/vignettes/installation.Rmd @@ -41,6 +41,6 @@ After completing these steps, your computer should be ready to use and export gr ## CMAP fonts -CMAP's design standards require the usage of the Whitney typeface. Whitney is not freely available, but rather requires a license. On CMAP computers, which should already have the Whitney font family installed, cmapplot will use Whitney without any issues. If you receive a warning that Whitney is not installed when you load the package, please verify that the Whitney fonts (specifically, the Book, Medium and Semibold variants) are installed in **C:\\Windows\\Fonts**. If it is not, please submit an IT helpdesk request to get it installed. If Whitney *is* already installed and you are receiving the warning message, please reach out to a member of the cmapplot development team. +CMAP's design standards require the usage of the Whitney typeface. Whitney is not freely available, but rather requires a license. On CMAP computers, which should already have the Whitney font family installed, cmapplot will use Whitney without any issues. If you receive a warning that Whitney is not installed when you load the package, please verify that the Whitney fonts (specifically, the Book, Medium and Semibold variants) are installed. If it is not, please submit an IT helpdesk request to get them installed. If Whitney *is* already installed and you are receiving the warning message, please reach out to a member of the cmapplot development team. -Non-CMAP users will have to license Whitney on their own, or else use cmapplot with its fall-back fonts: Calibri (on Windows) or Arial (on macOS/Linux). +Non-CMAP users will have to license Whitney on their own, or else use cmapplot without. The package will default to your system's default sans-serif font, which is likely Arial. diff --git a/vignettes/plots.Rmd b/vignettes/plots.Rmd index 39224d85..6fce73bd 100644 --- a/vignettes/plots.Rmd +++ b/vignettes/plots.Rmd @@ -14,7 +14,8 @@ knitr::opts_chunk$set( fig.width = 7, fig.asp = 400/670, fig.retina = 4, - fig.align = "center" + fig.align = "center", + dev = "ragg_png" ) library(tidyverse) From 9ca3cd96f98c84166aec046bdc14decef378c297 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 4 Apr 2021 23:22:28 -0500 Subject: [PATCH 13/83] set global tweak --- R/cmapplot_globals.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 8eb7e2b9..bf480428 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -161,8 +161,8 @@ get_cmapplot_global <- function(...){ #' @export set_cmapplot_global <- function(value, ..., quietly = FALSE){ - # do a full get to make sure the variable exists. - # this is a throw-away, just used to as a check + # do a get of the specific attribute to make sure it exists. + # this will error if the path is null p <- get_cmapplot_global(...) # establish vector of sublocations @@ -174,8 +174,12 @@ set_cmapplot_global <- function(value, ..., quietly = FALSE){ # build a string to evaluate that modifies some element of the item. str <- paste0( "item", - ifelse(length(names)>1, paste0("$", paste(names[-1], collapse = "$")),""), - "<- '", value, "'") + if(length(names)>1){ paste0("$", paste(names[-1], collapse = "$"))} else {""}, + "<- ", + if(!is.numeric(value)) {"'"} else {""}, + value, + if(!is.numeric(value)) {"'"} else {""} + ) # replace the specific item by evaluating the string eval(parse(text = str)) From 44fa37b6ac8aa531de50e79479679d6d8f6ef526 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 5 Apr 2021 00:39:13 -0500 Subject: [PATCH 14/83] Update DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index 1e6e1291..8159c1f0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,6 +48,7 @@ Imports: lubridate, magrittr, purrr, + ragg, rlang, scales, stringr, From d8d99d783b75d11b89d5cf36dafafb441cb47feb Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:05:11 -0500 Subject: [PATCH 15/83] Move helper functions into utilities.R --- R/cmapplot.R | 123 +++----------------------------------------------- R/utilities.R | 99 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 117 deletions(-) create mode 100644 R/utilities.R diff --git a/R/cmapplot.R b/R/cmapplot.R index 490a25c7..02e020c8 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -11,17 +11,13 @@ #' #' @name cmapplot #' @docType package -#' @import ggplot2 dplyr grid scales grDevices graphics rlang gridtext +#' @import dplyr ggplot2 graphics grDevices grid gridtext rlang scales systemfonts #' @importFrom glue glue glue_collapse #' @keywords internal "_PACKAGE" - - - -## Update fonts based on system -- *must* be done with .onLoad() -#' @import systemfonts +# Update fonts based on system -- *must* be done with .onLoad() .onLoad <- function(...) { family <- name <- path <- NULL @@ -40,10 +36,9 @@ # Update font variables assign("font", - list( - strong = list(family = "Whitney-Semibold", face = "plain"), - regular = list(family = "Whitney-Medium", face = "plain"), - light = list(family = "Whitney-Book", face = "plain")), + list(strong = list(family = "Whitney-Semibold", face = "plain"), + regular = list(family = "Whitney-Medium", face = "plain"), + light = list(family = "Whitney-Book", face = "plain")), envir = cmapplot_globals) } @@ -62,113 +57,7 @@ .onAttach <- function(...){ if(!get("use_whitney", envir = cmapplot_globals)){ packageStartupMessage( - "WARNING: Whitney is not installed on this machine, so CMAP theme will use your default sans-Serif font" + "WARNING: Whitney was not found on this machine, so CMAP theme will use your default sans-serif font" ) } } - - - - -# Font spec visualization helper function --------------------------------- - -#' Font visualization test -#' -#' This internal function uses base R graphics to display the five text variants -#' that should show up on a cmap themed graphic - and what fonts the package is -#' planning to use to display them. -#' -#' @noRd -display_cmap_fonts <- function() { - graphics::plot(c(0,2), c(0,6), type="n", xlab="", ylab="") - - draw.me <- function(name, font, size, placement){ - thisfont <- cmapplot_globals$font[[font]] - thissize <- cmapplot_globals$fsize[[size]] - - graphics::par(family=thisfont$family, - font=ifelse(thisfont$face == "bold", 2, 1)) - graphics::text(1, placement, - paste(name, - paste(paste("font:", font), paste("size:", size), sep = ", "), - paste(thisfont$family, thisfont$face, thissize, sep = ", "), - sep = " | "), - cex=thissize/12, ps=12) - } - - draw.me(name = "Title", font = "strong", size = "L", 5) - draw.me(name = "Main", font = "regular", size = "M", 4) - draw.me(name = "Axis", font = "light", size = "M", 3) - draw.me(name = "Label", font = "strong", size = "M", 2) - draw.me(name = "Note", font = "light", size = "S", 1) -} - - -# Plot sizes and colors --------------------------------------------------- - - -#' Line width conversion -#' -#' The factor \code{.lwd} is used to calculate correct output sizes for line -#' widths. For line widths in \code{ggplot2}, the size in mm must be divided -#' by this factor for correct output. Because the user is likely to prefer -#' other units besides for mm, \code{gg_lwd_convert()} is provided as a -#' convenience function, converting from any unit all the way to ggplot units. -#' -#' \code{.lwd} is equal to \code{ggplot2::.stroke / ggplot2::.pt}. In -#' \code{ggplot2}, the size in mm is divided by \code{.lwd} to achieve the -#' correct output. In the \code{grid} package, however, the size in points -#' (\code{pts} (or maybe \code{bigpts}? Unclear.) must be divided by -#' \code{.lwd}. The user is unlikely to interact directly with \code{grid}, -#' but this is how \code{finalize_plot()} does its work. -#' -#' This is closely related to \code{ggplot::.pt}, which is the factor that -#' font sizes (in \code{pts}) must be divided by for text geoms within -#' \code{ggplot2}. Confusingly, \code{.pt} is not required for \code{ggplot2} -#' font sizes outside the plot area: e.g. axis titles, etc. -#' -#' @seealso grid's \code{\link[grid]{unit}}, ggplot2's -#' \code{\link[ggplot2]{.pt}}, and -#' \url{https://stackoverflow.com/questions/17311917/ggplot2-the-unit-of-size} -#' -#' @examples -#' ggplot() + coord_cartesian(xlim = c(-3, 3), ylim = c(-3, 3)) + -#' -#' # a green line 3 points wide -#' geom_hline(yintercept = 1, color = "green", size = gg_lwd_convert(3)) + -#' -#' # black text of size 24 points -#' annotate("text", -2, 0, label = "text", size = 24/ggplot2::.pt) -#' -#' -#' # a blue line 6 points wide, drawn over the plot with the `grid` package -#' grid::grid.lines(y = 0.4, -#' gp = grid::gpar(col = "blue", lwd = 6 / .lwd)) -#' -#' -#' @export -.lwd <- ggplot2::.pt / ggplot2::.stroke - - -#' Helper function to calculate correct size for ggplot line widths. -#' -#' @param value Numeric, the value to be converted. -#' @param unit Char, the unit of the value to be converted. Can be any of the -#' units accepted by \code{grid::unit()}, including "bigpts", "pt", "mm", and -#' "in". Default is \code{bigpts}. -#' -#' @describeIn dot-lwd Function to convert from any unit directly to ggplot2's -#' preferred millimeters. -#' -#' @export -gg_lwd_convert <- function(value, unit = "bigpts") { - - # convert input type to mm - value_out <- grid::convertUnit(grid::unit(value, unit), "mm", valueOnly = TRUE) - - # return with conversion factor - return( - value_out / .lwd - ) -} - diff --git a/R/utilities.R b/R/utilities.R new file mode 100644 index 00000000..5dc3b24d --- /dev/null +++ b/R/utilities.R @@ -0,0 +1,99 @@ +# Font spec visualization helper function --------------------------------- + +#' Font visualization test +#' +#' This internal function uses base R graphics to display the five text variants +#' that should show up on a cmap themed graphic - and what fonts the package is +#' planning to use to display them. +#' +#' @noRd +display_cmap_fonts <- function() { + graphics::plot(c(0,2), c(0,6), type="n", xlab="", ylab="") + + draw.me <- function(name, font, size, placement){ + thisfont <- cmapplot_globals$font[[font]] + thissize <- cmapplot_globals$fsize[[size]] + + graphics::par(family=thisfont$family, + font=ifelse(thisfont$face == "bold", 2, 1)) + graphics::text(1, placement, + paste(name, + paste(paste("font:", font), paste("size:", size), sep = ", "), + paste(thisfont$family, thisfont$face, thissize, sep = ", "), + sep = " | "), + cex=thissize/12, ps=12) + } + + draw.me(name = "Title", font = "strong", size = "L", 5) + draw.me(name = "Main", font = "regular", size = "M", 4) + draw.me(name = "Axis", font = "light", size = "M", 3) + draw.me(name = "Label", font = "strong", size = "M", 2) + draw.me(name = "Note", font = "light", size = "S", 1) +} + + + +# Plot sizes and colors --------------------------------------------------- + +#' Line width conversion +#' +#' The factor \code{.lwd} is used to calculate correct output sizes for line +#' widths. For line widths in \code{ggplot2}, the size in mm must be divided +#' by this factor for correct output. Because the user is likely to prefer +#' other units besides for mm, \code{gg_lwd_convert()} is provided as a +#' convenience function, converting from any unit all the way to ggplot units. +#' +#' \code{.lwd} is equal to \code{ggplot2::.stroke / ggplot2::.pt}. In +#' \code{ggplot2}, the size in mm is divided by \code{.lwd} to achieve the +#' correct output. In the \code{grid} package, however, the size in points +#' (\code{pts} (or maybe \code{bigpts}? Unclear.) must be divided by +#' \code{.lwd}. The user is unlikely to interact directly with \code{grid}, +#' but this is how \code{finalize_plot()} does its work. +#' +#' This is closely related to \code{ggplot::.pt}, which is the factor that +#' font sizes (in \code{pts}) must be divided by for text geoms within +#' \code{ggplot2}. Confusingly, \code{.pt} is not required for \code{ggplot2} +#' font sizes outside the plot area: e.g. axis titles, etc. +#' +#' @seealso grid's \code{\link[grid]{unit}}, ggplot2's +#' \code{\link[ggplot2]{.pt}}, and +#' \url{https://stackoverflow.com/questions/17311917/ggplot2-the-unit-of-size} +#' +#' @examples +#' ggplot() + coord_cartesian(xlim = c(-3, 3), ylim = c(-3, 3)) + +#' +#' # a green line 3 points wide +#' geom_hline(yintercept = 1, color = "green", size = gg_lwd_convert(3)) + +#' +#' # black text of size 24 points +#' annotate("text", -2, 0, label = "text", size = 24/ggplot2::.pt) +#' +#' +#' # a blue line 6 points wide, drawn over the plot with the `grid` package +#' grid::grid.lines(y = 0.4, gp = grid::gpar(col = "blue", lwd = 6 / .lwd)) +#' +#' @export +.lwd <- ggplot2::.pt / ggplot2::.stroke + + +#' Helper function to calculate correct size for ggplot line widths. +#' +#' @param value Numeric, the value to be converted. +#' @param unit Char, the unit of the value to be converted. Can be any of the +#' units accepted by \code{grid::unit()}, including "bigpts", "pt", "mm", and +#' "in". Default is \code{bigpts}. +#' +#' @describeIn dot-lwd Function to convert from any unit directly to ggplot2's +#' preferred millimeters. +#' +#' @export +gg_lwd_convert <- function(value, unit = "bigpts") { + + # convert input type to mm + value_out <- grid::convertUnit(grid::unit(value, unit), "mm", valueOnly = TRUE) + + # return with conversion factor + return( + value_out / .lwd + ) +} From 91697944974dd34822e87898476a03b1f0dd0ff9 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:05:28 -0500 Subject: [PATCH 16/83] Minor edits --- R/cmapplot_globals.R | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index bf480428..ef33943c 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -1,27 +1,27 @@ -# establish location for cmapplot global variables +# Initialize environment for cmapplot global variables cmapplot_globals <- new.env(parent = emptyenv()) -# set up default font handling -# (overridden if local machine has Whitney in .onLoad) +# Set up default font handling +# (Note: overridden by .onLoad() if Whitney is available) cmapplot_globals$use_whitney <- FALSE cmapplot_globals$font <- list( strong = list(family = "sans", face = "bold"), regular = list(family = "sans", face = "plain"), light = list(family = "sans", face = "plain")) -# establish font sizes +# Set common font sizes cmapplot_globals$fsize <- list( S = 11, M = 14, L = 17 ) -## Colors +# Define CMAP colors cmapplot_globals$colors <- list( blackish = "#222222" ) -## Establish plotting constants in bigpts (1/72 of inch) +# Establish plotting constants in bigpts (1/72 of inch) cmapplot_globals$consts <- list( lwd_gridline = 0.3, lwd_strongline = 1, @@ -174,11 +174,9 @@ set_cmapplot_global <- function(value, ..., quietly = FALSE){ # build a string to evaluate that modifies some element of the item. str <- paste0( "item", - if(length(names)>1){ paste0("$", paste(names[-1], collapse = "$"))} else {""}, - "<- ", - if(!is.numeric(value)) {"'"} else {""}, - value, - if(!is.numeric(value)) {"'"} else {""} + ifelse(length(names) > 1, paste0("$", paste(names[-1], collapse = "$")), ""), + " <- ", + ifelse(!is.numeric(value), paste0("'", value, "'"), value) ) # replace the specific item by evaluating the string @@ -195,6 +193,5 @@ set_cmapplot_global <- function(value, ..., quietly = FALSE){ "New value: '", value, "'" )) } - invisible() } From f87e295ac95f37036f91412281dade17648bfc72 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:15:00 -0500 Subject: [PATCH 17/83] Moved geoms_that_change definition into cmapplot_globals.R --- R/cmapplot_globals.R | 11 +++++++++++ R/default_aes.R | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index ef33943c..178209cc 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -44,6 +44,17 @@ cmapplot_globals$consts <- list( leading_caption = 1 ) +# List of all geoms whose aesthetics will be modified by cmapplot +cmapplot_globals$geoms_that_change <- c( + "Label", + "Line", + "Text", + "TextLast", + "PointLast", + "RecessionsText" +) + + #'The cmapplot_globals environment #' #'The \code{cmapplot_globals} environment contains a list of predefined diff --git a/R/default_aes.R b/R/default_aes.R index 0329588e..4cf716d8 100644 --- a/R/default_aes.R +++ b/R/default_aes.R @@ -1,14 +1,3 @@ -# list of all geoms whose aesthetics will be customized -cmapplot_globals$geoms_that_change <- c( - "Label", - "Line", - "Text", - "TextLast", - "PointLast", - "RecessionsText" -) - - #' Initialize CMAP `default_aes` values #' #' Internal function to load in default aesthetics for modified geoms. From 62896164214f7c0bd19842470289572936465f64 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:26:14 -0500 Subject: [PATCH 18/83] Fixed typo --- R/default_aes.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/default_aes.R b/R/default_aes.R index 4cf716d8..7cdc7a26 100644 --- a/R/default_aes.R +++ b/R/default_aes.R @@ -58,7 +58,7 @@ init_cmap_default_aes <- function () { #' style standards, because (at least at the moment) setting geom aesthetic #' defaults on a plot-by-plot basis (such as with \code{ggplot2::theme}) is not #' possible. The geoms impacted are stored in -#' \code{cmapplot_globals$geoms_to_change}. +#' \code{cmapplot_globals$geoms_that_change}. #' #' These functions are employed implicitly within \code{\link{finalize_plot}} to #' apply preferred aesthetic defaults to final outputs. They are only necessary From eed080699f1ac9a11b6382331ebfdffa0b571c40 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:26:36 -0500 Subject: [PATCH 19/83] Added note about font size units --- R/cmapplot_globals.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 178209cc..d0df1c74 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -9,7 +9,7 @@ cmapplot_globals$font <- list( regular = list(family = "sans", face = "plain"), light = list(family = "sans", face = "plain")) -# Set common font sizes +# Set common font sizes (bigpts) cmapplot_globals$fsize <- list( S = 11, M = 14, From 3f345bfa2ee493b7af5b9be7b77682377df597a8 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 12:30:21 -0500 Subject: [PATCH 20/83] Rebuilt documentation --- man/cmap_default_aes.Rd | 2 +- man/dot-lwd.Rd | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/man/cmap_default_aes.Rd b/man/cmap_default_aes.Rd index 44b99680..4c43639d 100644 --- a/man/cmap_default_aes.Rd +++ b/man/cmap_default_aes.Rd @@ -19,7 +19,7 @@ certain ggplot2 geoms. This is necessary for geoms to be "themed" to CMAP style standards, because (at least at the moment) setting geom aesthetic defaults on a plot-by-plot basis (such as with \code{ggplot2::theme}) is not possible. The geoms impacted are stored in -\code{cmapplot_globals$geoms_to_change}. +\code{cmapplot_globals$geoms_that_change}. } \details{ These functions are employed implicitly within \code{\link{finalize_plot}} to diff --git a/man/dot-lwd.Rd b/man/dot-lwd.Rd index 00356df8..62765db2 100644 --- a/man/dot-lwd.Rd +++ b/man/dot-lwd.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cmapplot.R +% Please edit documentation in R/utilities.R \docType{data} \name{.lwd} \alias{.lwd} @@ -57,9 +57,7 @@ ggplot() + coord_cartesian(xlim = c(-3, 3), ylim = c(-3, 3)) + # a blue line 6 points wide, drawn over the plot with the `grid` package -grid::grid.lines(y = 0.4, - gp = grid::gpar(col = "blue", lwd = 6 / .lwd)) - +grid::grid.lines(y = 0.4, gp = grid::gpar(col = "blue", lwd = 6 / .lwd)) } \seealso{ From c4dcaa1650331e5987757f07ba3ac0cbb3bd2e97 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 15:32:35 -0500 Subject: [PATCH 21/83] Corrected font size note Proving the point of why this needed to be added :) --- R/cmapplot_globals.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index d0df1c74..3231b7e1 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -9,7 +9,7 @@ cmapplot_globals$font <- list( regular = list(family = "sans", face = "plain"), light = list(family = "sans", face = "plain")) -# Set common font sizes (bigpts) +# Set common font sizes (pts) cmapplot_globals$fsize <- list( S = 11, M = 14, From 44fbb8373295612bc8da5b6459354cf1e8d9ebcd Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 15:46:47 -0500 Subject: [PATCH 22/83] Create test pkgdown action View results locally in gh-pages-test branch --- .github/workflows/pkgdown_test.yaml | 72 +++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/pkgdown_test.yaml diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml new file mode 100644 index 00000000..14f862d5 --- /dev/null +++ b/.github/workflows/pkgdown_test.yaml @@ -0,0 +1,72 @@ +# Automatically rebuilds pkgdown website any time master branch is updated. +# Based on . +on: + push: + branches: systemfonts + +name: pkgdown_systemfonts_test + +jobs: + pkgdown: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Checkout CMAP fonts repo + uses: actions/checkout@v2 + with: + repository: CMAP-REPOS/cmap-fonts + token: ${{ secrets.CMAP_REPO_FULL_ACCESS }} + path: cmap-fonts + + - name: Install CMAP fonts for R access + # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f + run: | + repo_dir="$GITHUB_WORKSPACE/cmap-fonts" + font_dir="$HOME/Library/Fonts" + mkdir -p $font_dir + find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" + eval $find_command | xargs -0 -I % + eval $find_command | xargs -0 -I % cp "%" "$font_dir/" + find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown") + shell: Rscript {0} + + - name: Check Whitney availability + run: | + all_fonts <- systemfonts::system_fonts() + message(paste(all_fonts$path[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE)' From 1b200fc30c4397d6a386db68703d5bf80ff47dd2 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 16:08:53 -0500 Subject: [PATCH 23/83] Rebuilt NAMESPACE --- NAMESPACE | 1 - 1 file changed, 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index e8b6c2a8..dd94c2c8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,7 +27,6 @@ export(geom_text_lastonly) export(get_cmapplot_global) export(get_cmapplot_globals) export(gg_lwd_convert) -export(integer_breaks) export(set_cmapplot_global) export(theme_cmap) export(unapply_cmap_default_aes) From 9db07e944c50dd936da62056983f6f9ee465bc85 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 16:09:03 -0500 Subject: [PATCH 24/83] Reference list tweaks --- pkgdown/_pkgdown.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index cff4c646..396cc842 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -22,13 +22,13 @@ reference: - title: Additional geoms & auxiliary functions - contents: - starts_with("geom_") - - cmap_default_aes + - ends_with("cmap_default_aes") - abbr_years -- title: Color Palettes and Gradients +- title: Color palettes & gradients - contents: - starts_with("viz_") - starts_with("cmap_fill_") -- title: Sample Datasets +- title: Sample datasets - contents: - cluster_jobchange - economy_basic @@ -41,7 +41,7 @@ reference: - vehicle_ownership - title: Lesser used objects - contents: - - ends_with("cmapplot_globals") + - contains("cmapplot_global") - gg_lwd_convert - update_recessions - customproto From 11db673d8b4b3e92f20b2a5bf0412df993a6ab42 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 16:27:13 -0500 Subject: [PATCH 25/83] Print all located font files in log --- .github/workflows/pkgdown_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 14f862d5..89bd4919 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -59,7 +59,8 @@ jobs: - name: Check Whitney availability run: | all_fonts <- systemfonts::system_fonts() - message(paste(all_fonts$path[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) + message(paste(all_fonts$path, collapse = "\n")) + message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) shell: Rscript {0} - name: Install package From 4da37df4f131b269376e56fd13a1227ebd45d3e4 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:07:46 -0500 Subject: [PATCH 26/83] Don't force all non-numeric types to character E.g. could not set TRUE or FALSE before --- R/cmapplot_globals.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 3231b7e1..85df09e4 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -187,7 +187,7 @@ set_cmapplot_global <- function(value, ..., quietly = FALSE){ "item", ifelse(length(names) > 1, paste0("$", paste(names[-1], collapse = "$")), ""), " <- ", - ifelse(!is.numeric(value), paste0("'", value, "'"), value) + ifelse(is.character(value), paste0("'", value, "'"), value) ) # replace the specific item by evaluating the string @@ -200,8 +200,8 @@ set_cmapplot_global <- function(value, ..., quietly = FALSE){ if(!quietly){ cat(paste0( "Item: ", paste(names, collapse = "$"), "\n", - "Old value: '", p, "'\n", - "New value: '", value, "'" + "Old value: ", ifelse(is.character(p), paste0("'", p, "'"), p), "\n", + "New value: ", ifelse(is.character(value), paste0("'", value, "'"), value) )) } invisible() From cc408161f37f83706f62f351689e39c4683ac266 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:20:34 -0500 Subject: [PATCH 27/83] Attempt to register fonts --- .github/workflows/pkgdown_test.yaml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 89bd4919..f32721f7 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -56,18 +56,28 @@ jobs: install.packages("pkgdown") shell: Rscript {0} - - name: Check Whitney availability - run: | - all_fonts <- systemfonts::system_fonts() - message(paste(all_fonts$path, collapse = "\n")) - message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) - shell: Rscript {0} + # - name: Check Whitney availability + # run: | + # all_fonts <- systemfonts::system_fonts() + # message(paste(all_fonts$path, collapse = "\n")) + # message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) + # shell: Rscript {0} - name: Install package run: R CMD INSTALL . - - name: Deploy package + - name: Set git config run: | git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE)' + + -name: Deploy package + run: | + font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") + font_files <- list.files(font_dir, pattern = "Whitney") + font_names <- stringr::str_extract(font_files, "^[^.]+") + font_paths <- paste(font_dir, font_files, sep = "/") + purrr::walk2(font_names, font_paths, systemfonts::register_font) + message(cmapplot::get_cmapplot_global("use_whitney")) + pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) + shell Rscript {0} From c3d3aa6c8cda872b6a67d6f64124472f4e097dfd Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:22:13 -0500 Subject: [PATCH 28/83] Corrected syntax issue --- .github/workflows/pkgdown_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index f32721f7..2fd9a143 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -80,4 +80,4 @@ jobs: purrr::walk2(font_names, font_paths, systemfonts::register_font) message(cmapplot::get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) - shell Rscript {0} + shell: Rscript {0} From 715fd28189942bd688691ca4f85c449c0a82b5e4 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:23:26 -0500 Subject: [PATCH 29/83] Corrected another syntax issue --- .github/workflows/pkgdown_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 2fd9a143..89031229 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -71,7 +71,7 @@ jobs: git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" - -name: Deploy package + - name: Deploy package run: | font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") font_files <- list.files(font_dir, pattern = "Whitney") From 5a4694583328fa83ec96089015f7bccd36d00381 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:33:35 -0500 Subject: [PATCH 30/83] Unload/reload cmapplot before deploy --- .github/workflows/pkgdown_test.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 89031229..9279dbdf 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -73,11 +73,15 @@ jobs: - name: Deploy package run: | + detach("package:cmapplot", unload = TRUE) font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") font_files <- list.files(font_dir, pattern = "Whitney") font_names <- stringr::str_extract(font_files, "^[^.]+") + message(font_names) font_paths <- paste(font_dir, font_files, sep = "/") + message(font_paths) purrr::walk2(font_names, font_paths, systemfonts::register_font) - message(cmapplot::get_cmapplot_global("use_whitney")) + library(cmapplot) + message(get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) shell: Rscript {0} From 130c5b2736902268575c0adb778276099c142052 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:39:34 -0500 Subject: [PATCH 31/83] Try devtools::reload() instead --- .github/workflows/pkgdown_test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 9279dbdf..1d7f86c2 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -73,7 +73,6 @@ jobs: - name: Deploy package run: | - detach("package:cmapplot", unload = TRUE) font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") font_files <- list.files(font_dir, pattern = "Whitney") font_names <- stringr::str_extract(font_files, "^[^.]+") @@ -81,7 +80,7 @@ jobs: font_paths <- paste(font_dir, font_files, sep = "/") message(font_paths) purrr::walk2(font_names, font_paths, systemfonts::register_font) - library(cmapplot) + devtools::reload() message(get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) shell: Rscript {0} From fdcf783a65db5a3e8bc049c0d3832ffc6a92cf20 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:46:52 -0500 Subject: [PATCH 32/83] One last attempt for the day... --- .github/workflows/pkgdown_test.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 1d7f86c2..164b82a0 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -76,11 +76,8 @@ jobs: font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") font_files <- list.files(font_dir, pattern = "Whitney") font_names <- stringr::str_extract(font_files, "^[^.]+") - message(font_names) font_paths <- paste(font_dir, font_files, sep = "/") - message(font_paths) purrr::walk2(font_names, font_paths, systemfonts::register_font) - devtools::reload() message(get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) shell: Rscript {0} From 32cb82251694da9f848093b8730d8449d9fbbe6b Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 5 Apr 2021 17:47:58 -0500 Subject: [PATCH 33/83] Just kidding, this is the real last attempt today --- .github/workflows/pkgdown_test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 164b82a0..e8aa3688 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -78,6 +78,7 @@ jobs: font_names <- stringr::str_extract(font_files, "^[^.]+") font_paths <- paste(font_dir, font_files, sep = "/") purrr::walk2(font_names, font_paths, systemfonts::register_font) + library(cmapplot) message(get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) shell: Rscript {0} From 9ec7364cf832b60c022dd974dbe820e69900d3f1 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Tue, 6 Apr 2021 09:56:55 -0500 Subject: [PATCH 34/83] Check for Whitney in systemfonts::registry_fonts() too --- R/cmapplot.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 02e020c8..f5db7d83 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -23,7 +23,11 @@ family <- name <- path <- NULL # check for Whitney - all_fonts <- systemfonts::system_fonts() + #all_fonts <- systemfonts::system_fonts() + all_fonts <- dplyr::bind_rows( + dplyr::select(systemfonts::system_fonts(), name, family, path), + dplyr::transmute(systemfonts::registry_fonts(), name = family, family = family, path = path) + ) whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_globals) From 2cfec6fcc42111fbd7369b6dbc2f77e616bdef0e Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Tue, 6 Apr 2021 09:57:22 -0500 Subject: [PATCH 35/83] Manually register fonts --- .github/workflows/pkgdown_test.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index e8aa3688..0764bca4 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -74,10 +74,9 @@ jobs: - name: Deploy package run: | font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - font_files <- list.files(font_dir, pattern = "Whitney") - font_names <- stringr::str_extract(font_files, "^[^.]+") - font_paths <- paste(font_dir, font_files, sep = "/") - purrr::walk2(font_names, font_paths, systemfonts::register_font) + systemfonts::register_font("Whitney-Book", plain=paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) + systemfonts::register_font("Whitney-Medium", plain=paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) + systemfonts::register_font("Whitney-Semibold", plain=paste0(font_dir, "/Whitney-Semibold-Adv.otf"), italic=paste0(font_dir, "/Whitney-SemiboldItal-Adv.otf")) library(cmapplot) message(get_cmapplot_global("use_whitney")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) From 608be33b04c0f3f90519adb27e68318742ef1cf9 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Tue, 6 Apr 2021 10:35:21 -0500 Subject: [PATCH 36/83] Print registry_fonts() family/path to log --- .github/workflows/pkgdown_test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 0764bca4..b3547954 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -77,7 +77,8 @@ jobs: systemfonts::register_font("Whitney-Book", plain=paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) systemfonts::register_font("Whitney-Medium", plain=paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) systemfonts::register_font("Whitney-Semibold", plain=paste0(font_dir, "/Whitney-Semibold-Adv.otf"), italic=paste0(font_dir, "/Whitney-SemiboldItal-Adv.otf")) + message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) library(cmapplot) message(get_cmapplot_global("use_whitney")) - pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE) + pkgdown::deploy_to_branch(branch="gh-pages-test", new_process=FALSE, clean=TRUE) shell: Rscript {0} From c022a2b844718fc8f9288a820fa3341da5f511e1 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Tue, 6 Apr 2021 17:14:09 -0500 Subject: [PATCH 37/83] a test --- .github/workflows/pkgdown_test.yaml | 2 ++ R/cmapplot.R | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index b3547954..9c6ef18d 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -80,5 +80,7 @@ jobs: message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) library(cmapplot) message(get_cmapplot_global("use_whitney")) + message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse = "\n")) + message(get_cmapplot_global("font$strong")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process=FALSE, clean=TRUE) shell: Rscript {0} diff --git a/R/cmapplot.R b/R/cmapplot.R index f5db7d83..c6b4913c 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -32,11 +32,11 @@ assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_globals) if(get("use_whitney", envir = cmapplot_globals)){ - # Register all Whitney fonts (note: this registers italic fonts both as - # variants of core fonts and as standalone fonts, so there is some - # duplication.) - whitney_fonts <- select(filter(all_fonts, family == "Whitney"), name, path) - purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) + # # Register all Whitney fonts (note: this registers italic fonts both as + # # variants of core fonts and as standalone fonts, so there is some + # # duplication.) + # whitney_fonts <- select(filter(all_fonts, family == "Whitney"), name, path) + # purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) # Update font variables assign("font", From 11dc0ffcf9ff620f36bf1767849d6d752a9562ae Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Tue, 6 Apr 2021 18:46:16 -0500 Subject: [PATCH 38/83] test 2 --- .github/workflows/pkgdown_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 9c6ef18d..b72735bd 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -73,6 +73,7 @@ jobs: - name: Deploy package run: | + systemfonts::clear::registry() font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") systemfonts::register_font("Whitney-Book", plain=paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) systemfonts::register_font("Whitney-Medium", plain=paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) @@ -80,7 +81,6 @@ jobs: message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) library(cmapplot) message(get_cmapplot_global("use_whitney")) - message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse = "\n")) - message(get_cmapplot_global("font$strong")) + message(paste(get_cmapplot_global("font"), collapse = " ")) pkgdown::deploy_to_branch(branch="gh-pages-test", new_process=FALSE, clean=TRUE) shell: Rscript {0} From f69c275ca42d58586a4583d141a2a5c968761598 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Tue, 6 Apr 2021 19:27:05 -0500 Subject: [PATCH 39/83] typo --- .github/workflows/pkgdown_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index b72735bd..3743e2db 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -73,7 +73,7 @@ jobs: - name: Deploy package run: | - systemfonts::clear::registry() + systemfonts::clear_registry() font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") systemfonts::register_font("Whitney-Book", plain=paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) systemfonts::register_font("Whitney-Medium", plain=paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) From 881a49675d2832fa7b66ecbd4a8d9de3cf772aad Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Tue, 6 Apr 2021 20:01:26 -0500 Subject: [PATCH 40/83] no italics? --- .github/workflows/pkgdown_test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 3743e2db..cb3dc8cb 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -75,9 +75,9 @@ jobs: run: | systemfonts::clear_registry() font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - systemfonts::register_font("Whitney-Book", plain=paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) - systemfonts::register_font("Whitney-Medium", plain=paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) - systemfonts::register_font("Whitney-Semibold", plain=paste0(font_dir, "/Whitney-Semibold-Adv.otf"), italic=paste0(font_dir, "/Whitney-SemiboldItal-Adv.otf")) + systemfonts::register_font("Whitney-Book", paste0(font_dir, "/Whitney-Book-Adv.otf")) + systemfonts::register_font("Whitney-Medium", paste0(font_dir, "/Whitney-Medium-Adv.otf")) + systemfonts::register_font("Whitney-Semibold", paste0(font_dir, "/Whitney-Semibold-Adv.otf")) message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) library(cmapplot) message(get_cmapplot_global("use_whitney")) From ac2932dd07aaa5b02fcf88a776609579fbeb9fb2 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Wed, 7 Apr 2021 10:45:21 -0500 Subject: [PATCH 41/83] Register fonts from cloned repo instead of ~/Library/Fonts --- .github/workflows/pkgdown_test.yaml | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index cb3dc8cb..db5d9f81 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -25,16 +25,16 @@ jobs: token: ${{ secrets.CMAP_REPO_FULL_ACCESS }} path: cmap-fonts - - name: Install CMAP fonts for R access - # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f - run: | - repo_dir="$GITHUB_WORKSPACE/cmap-fonts" - font_dir="$HOME/Library/Fonts" - mkdir -p $font_dir - find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" - eval $find_command | xargs -0 -I % - eval $find_command | xargs -0 -I % cp "%" "$font_dir/" - find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % + # - name: Install CMAP fonts for R access + # # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f + # run: | + # repo_dir="$GITHUB_WORKSPACE/cmap-fonts" + # font_dir="$HOME/Library/Fonts" + # mkdir -p $font_dir + # find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" + # eval $find_command | xargs -0 -I % + # eval $find_command | xargs -0 -I % cp "%" "$font_dir/" + # find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % - name: Query dependencies run: | @@ -73,11 +73,10 @@ jobs: - name: Deploy package run: | - systemfonts::clear_registry() - font_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - systemfonts::register_font("Whitney-Book", paste0(font_dir, "/Whitney-Book-Adv.otf")) - systemfonts::register_font("Whitney-Medium", paste0(font_dir, "/Whitney-Medium-Adv.otf")) - systemfonts::register_font("Whitney-Semibold", paste0(font_dir, "/Whitney-Semibold-Adv.otf")) + font_dir <- paste0(Sys.getenv("GITHUB_WORKSPACE"), "/cmap-fonts") + systemfonts::register_font("Whitney-Book", paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) + systemfonts::register_font("Whitney-Medium", paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) + systemfonts::register_font("Whitney-Semibold", paste0(font_dir, "/Whitney-Semibold-Adv.otf"), italic=paste0(font_dir, "/Whitney-SemiboldItal-Adv.otf")) message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) library(cmapplot) message(get_cmapplot_global("use_whitney")) From f4e8d1bd35703beae01cd0d48569bb89ff57ad73 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sat, 10 Apr 2021 07:14:53 -0500 Subject: [PATCH 42/83] print font registry in vignette --- vignettes/finalize.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 84520827..8c27df4a 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r setup, include = FALSE} +```{r setup} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", @@ -43,6 +43,8 @@ p <- ggplot(data = df, nudge_x = 0.5) + coord_cartesian(clip = "off") + theme_cmap() + +systemfonts::registry_fonts() ``` `finalize_plot()` will place a ggplot into a frame defined by CMAP design standards. It will align your title and caption to the left, add a horizontal line on top, and make other adjustments. It can show you the final plot and/or export it as a raster or vector file. This function will not apply CMAP design standards to the plot itself; use `theme_cmap()` for that. From 418944fa792bfe0c9981bec06adb8f4911adeded Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 17:29:28 -0500 Subject: [PATCH 43/83] print contents of VM font folder --- .github/workflows/pkgdown_test.yaml | 35 ++++++++++++++++------------- R/cmapplot.R | 9 ++++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index db5d9f81..c4d10307 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -25,16 +25,16 @@ jobs: token: ${{ secrets.CMAP_REPO_FULL_ACCESS }} path: cmap-fonts - # - name: Install CMAP fonts for R access - # # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f - # run: | - # repo_dir="$GITHUB_WORKSPACE/cmap-fonts" - # font_dir="$HOME/Library/Fonts" - # mkdir -p $font_dir - # find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" - # eval $find_command | xargs -0 -I % - # eval $find_command | xargs -0 -I % cp "%" "$font_dir/" - # find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % + - name: Install CMAP fonts for R access + # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f + run: | + repo_dir="$GITHUB_WORKSPACE/cmap-fonts" + font_dir="$HOME/Library/Fonts" + mkdir -p $font_dir + find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" + eval $find_command | xargs -0 -I % + eval $find_command | xargs -0 -I % cp "%" "$font_dir/" + find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % - name: Query dependencies run: | @@ -56,12 +56,15 @@ jobs: install.packages("pkgdown") shell: Rscript {0} - # - name: Check Whitney availability - # run: | - # all_fonts <- systemfonts::system_fonts() - # message(paste(all_fonts$path, collapse = "\n")) - # message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) - # shell: Rscript {0} + - name: Check Whitney availability + run: | + all_fonts <- systemfonts::system_fonts() + message("CONTENTS OF SYSTEMFONTS:") + message(paste(all_fonts$path, collapse = "\n")) + message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) + message("CONTENTS OF USER FONT FILE:") + message(paste(list.files(paste0(Sys.getenv("HOME"), "/Library/Fonts")), collapse = "\n")) + shell: Rscript {0} - name: Install package run: R CMD INSTALL . diff --git a/R/cmapplot.R b/R/cmapplot.R index c6b4913c..c5e4991d 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -24,13 +24,14 @@ # check for Whitney #all_fonts <- systemfonts::system_fonts() - all_fonts <- dplyr::bind_rows( - dplyr::select(systemfonts::system_fonts(), name, family, path), - dplyr::transmute(systemfonts::registry_fonts(), name = family, family = family, path = path) - ) + all_fonts <- systemfonts::system_fonts() whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_globals) + if(!get("use_whitney", envir = cmapplot_globals)){ + + } + if(get("use_whitney", envir = cmapplot_globals)){ # # Register all Whitney fonts (note: this registers italic fonts both as # # variants of core fonts and as standalone fonts, so there is some From 4b9e6479a6666ab2da41a56eec3bb35bdcd8b4a2 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 17:44:05 -0500 Subject: [PATCH 44/83] clean up pkgdown GHA --- .github/workflows/pkgdown_test.yaml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index c4d10307..8ee2bebb 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -59,30 +59,19 @@ jobs: - name: Check Whitney availability run: | all_fonts <- systemfonts::system_fonts() - message("CONTENTS OF SYSTEMFONTS:") - message(paste(all_fonts$path, collapse = "\n")) + message("FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) - message("CONTENTS OF USER FONT FILE:") - message(paste(list.files(paste0(Sys.getenv("HOME"), "/Library/Fonts")), collapse = "\n")) + user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") + message(paste0("CONTENTS OF ", user_dir, ":") + message(paste(list.files(), collapse = "\n")) shell: Rscript {0} - name: Install package run: R CMD INSTALL . - - name: Set git config - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - name: Deploy package run: | - font_dir <- paste0(Sys.getenv("GITHUB_WORKSPACE"), "/cmap-fonts") - systemfonts::register_font("Whitney-Book", paste0(font_dir, "/Whitney-Book-Adv.otf"), italic=paste0(font_dir, "/Whitney-BookItal-Adv.otf")) - systemfonts::register_font("Whitney-Medium", paste0(font_dir, "/Whitney-Medium-Adv.otf"), italic=paste0(font_dir, "/Whitney-MediumItal-Adv.otf")) - systemfonts::register_font("Whitney-Semibold", paste0(font_dir, "/Whitney-Semibold-Adv.otf"), italic=paste0(font_dir, "/Whitney-SemiboldItal-Adv.otf")) - message(paste(systemfonts::registry_fonts()$family, systemfonts::registry_fonts()$path, collapse="\n")) - library(cmapplot) - message(get_cmapplot_global("use_whitney")) - message(paste(get_cmapplot_global("font"), collapse = " ")) - pkgdown::deploy_to_branch(branch="gh-pages-test", new_process=FALSE, clean=TRUE) - shell: Rscript {0} + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE)' From da5ab92a235548e4440d24babcf60ec1a6b43ebd Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 17:46:10 -0500 Subject: [PATCH 45/83] typo --- .github/workflows/pkgdown_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 8ee2bebb..52188813 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -62,7 +62,7 @@ jobs: message("FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - message(paste0("CONTENTS OF ", user_dir, ":") + message(paste0("CONTENTS OF ", user_dir, ":")) message(paste(list.files(), collapse = "\n")) shell: Rscript {0} From 3b08605be8669b7f5d35be705bdbea16c71c8683 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 17:51:14 -0500 Subject: [PATCH 46/83] tweak font dir --- .github/workflows/pkgdown_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 52188813..7fb22ba5 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -61,7 +61,7 @@ jobs: all_fonts <- systemfonts::system_fonts() message("FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) - user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") + user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts/cmap-fonts") message(paste0("CONTENTS OF ", user_dir, ":")) message(paste(list.files(), collapse = "\n")) shell: Rscript {0} From 524f73a58dc9a5f5b11330d186fe4da2605b3456 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 17:57:36 -0500 Subject: [PATCH 47/83] another typo --- .github/workflows/pkgdown_test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 7fb22ba5..0b0c6d66 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -61,9 +61,9 @@ jobs: all_fonts <- systemfonts::system_fonts() message("FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) - user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts/cmap-fonts") + user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") message(paste0("CONTENTS OF ", user_dir, ":")) - message(paste(list.files(), collapse = "\n")) + message(paste(list.files(user_dir), collapse = "\n")) shell: Rscript {0} - name: Install package From a8ba10057bd7fa1f58d3f8b14aef9864754fba5b Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 18:52:25 -0500 Subject: [PATCH 48/83] mac font registration attempt 1 --- .github/workflows/pkgdown_test.yaml | 4 ++-- R/cmapplot.R | 29 ++++++++++++++++++----------- vignettes/finalize.Rmd | 4 +--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 0b0c6d66..0a73aafe 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -59,8 +59,8 @@ jobs: - name: Check Whitney availability run: | all_fonts <- systemfonts::system_fonts() - message("FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") - message(paste(all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")], collapse = "\n")) + message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") + message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") message(paste0("CONTENTS OF ", user_dir, ":")) message(paste(list.files(user_dir), collapse = "\n")) diff --git a/R/cmapplot.R b/R/cmapplot.R index c5e4991d..be8d634f 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -23,23 +23,30 @@ family <- name <- path <- NULL # check for Whitney - #all_fonts <- systemfonts::system_fonts() all_fonts <- systemfonts::system_fonts() - whitney_core <- all_fonts$name[all_fonts$name %in% c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold")] - assign("use_whitney", length(whitney_core) >= 3, envir = cmapplot_globals) + whitney_core <- c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold") + assign("use_whitney", + length(all_fonts$name[all_fonts$name %in% whitney_core]) >= 3, + envir = cmapplot_globals) - if(!get("use_whitney", envir = cmapplot_globals)){ + # If on a Mac, and !use_whitney, attempt to register from user's fonts folder + ## SHOULD THIS BE CHANGED TO ONLY IMPACT THE VM? SUCH AS USER == "runner"??? + if(.Platform$OS.type != "windows" & !get("use_whitney", envir = cmapplot_globals)){ + # attempt to register fonts in user's fonts folder + ## SHOULD THIS BE CHANGED TO ONLY WHITNEY FONTS? + user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") + user_font_names <- sub("-Adv.otf$", "", list.files(user_dir)) + user_font_paths <- list.files(user_dir, full.names = TRUE) + purr::walk2(user_font_names, user_font_paths, systemfonts::register_font) + registry_fonts <- systemfonts::registry_fonts() + assign("use_whitney", + length(registry_fonts$name[registry_fonts$name %in% whitney_core]) >= 3, + envir = cmapplot_globals) } + # Update font names if(get("use_whitney", envir = cmapplot_globals)){ - # # Register all Whitney fonts (note: this registers italic fonts both as - # # variants of core fonts and as standalone fonts, so there is some - # # duplication.) - # whitney_fonts <- select(filter(all_fonts, family == "Whitney"), name, path) - # purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) - - # Update font variables assign("font", list(strong = list(family = "Whitney-Semibold", face = "plain"), regular = list(family = "Whitney-Medium", face = "plain"), diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 8c27df4a..84520827 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r setup} +```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", @@ -43,8 +43,6 @@ p <- ggplot(data = df, nudge_x = 0.5) + coord_cartesian(clip = "off") + theme_cmap() - -systemfonts::registry_fonts() ``` `finalize_plot()` will place a ggplot into a frame defined by CMAP design standards. It will align your title and caption to the left, add a horizontal line on top, and make other adjustments. It can show you the final plot and/or export it as a raster or vector file. This function will not apply CMAP design standards to the plot itself; use `theme_cmap()` for that. From ad921baddc64067fc3b29c5b6759e26ffd7a81f6 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 18:54:07 -0500 Subject: [PATCH 49/83] typo --- R/cmapplot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index be8d634f..a8a9da9b 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -37,7 +37,7 @@ user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") user_font_names <- sub("-Adv.otf$", "", list.files(user_dir)) user_font_paths <- list.files(user_dir, full.names = TRUE) - purr::walk2(user_font_names, user_font_paths, systemfonts::register_font) + purrr::walk2(user_font_names, user_font_paths, systemfonts::register_font) registry_fonts <- systemfonts::registry_fonts() assign("use_whitney", From a20eb26ab09483d7fb877861d0736fccc7bcf4f0 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 11 Apr 2021 21:01:27 -0500 Subject: [PATCH 50/83] new branch --- .github/workflows/pkgdown_test.yaml | 2 +- vignettes/finalize.Rmd | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 0a73aafe..7bf11fac 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -74,4 +74,4 @@ jobs: run: | git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", new_process = FALSE, clean = TRUE)' + Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test2", clean = TRUE)' diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 84520827..8c27df4a 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r setup, include = FALSE} +```{r setup} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", @@ -43,6 +43,8 @@ p <- ggplot(data = df, nudge_x = 0.5) + coord_cartesian(clip = "off") + theme_cmap() + +systemfonts::registry_fonts() ``` `finalize_plot()` will place a ggplot into a frame defined by CMAP design standards. It will align your title and caption to the left, add a horizontal line on top, and make other adjustments. It can show you the final plot and/or export it as a raster or vector file. This function will not apply CMAP design standards to the plot itself; use `theme_cmap()` for that. From 1b519aca6e4a73b6e4b8e413140e7edf8d8d863c Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 16 Apr 2021 16:38:41 -0500 Subject: [PATCH 51/83] test --- R/cmapplot.R | 1 + vignettes/finalize.Rmd | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index a8a9da9b..9d986c55 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -40,6 +40,7 @@ purrr::walk2(user_font_names, user_font_paths, systemfonts::register_font) registry_fonts <- systemfonts::registry_fonts() + message(paste(registry_fonts, collapse = "\n")) ## temp assign("use_whitney", length(registry_fonts$name[registry_fonts$name %in% whitney_core]) >= 3, envir = cmapplot_globals) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 8c27df4a..382b7c67 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -44,7 +44,7 @@ p <- ggplot(data = df, coord_cartesian(clip = "off") + theme_cmap() -systemfonts::registry_fonts() +systemfonts::registry_fonts() ``` `finalize_plot()` will place a ggplot into a frame defined by CMAP design standards. It will align your title and caption to the left, add a horizontal line on top, and make other adjustments. It can show you the final plot and/or export it as a raster or vector file. This function will not apply CMAP design standards to the plot itself; use `theme_cmap()` for that. From 013787bbeac492d47377b356c811c4f0bf4b0f5d Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 16 Apr 2021 16:46:24 -0500 Subject: [PATCH 52/83] typo --- R/cmapplot.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 9d986c55..95cc169f 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -40,9 +40,9 @@ purrr::walk2(user_font_names, user_font_paths, systemfonts::register_font) registry_fonts <- systemfonts::registry_fonts() - message(paste(registry_fonts, collapse = "\n")) ## temp + message(length(registry_fonts$family[registry_fonts$family %in% whitney_core])) ## temp assign("use_whitney", - length(registry_fonts$name[registry_fonts$name %in% whitney_core]) >= 3, + length(registry_fonts$family[registry_fonts$family %in% whitney_core]) >= 3, envir = cmapplot_globals) } From 51b8f242e3fedf8a123e63e5bdc245cb5f7b8b68 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 19 Apr 2021 01:41:33 -0500 Subject: [PATCH 53/83] getting things working again --- .github/workflows/pkgdown_test.yaml | 4 +- R/cmapplot.R | 57 +++++++++++++++++++---------- R/utilities.R | 26 +++++++++++++ 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 7bf11fac..a5a72b11 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -56,13 +56,13 @@ jobs: install.packages("pkgdown") shell: Rscript {0} - - name: Check Whitney availability + - name: Check Whitney availability in R run: | all_fonts <- systemfonts::system_fonts() message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - message(paste0("CONTENTS OF ", user_dir, ":")) + message(paste0("CONTENTS OF ", user_dir, " (MUST BE REGISTERED):")) message(paste(list.files(user_dir), collapse = "\n")) shell: Rscript {0} diff --git a/R/cmapplot.R b/R/cmapplot.R index 95cc169f..0cc8e781 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -22,28 +22,45 @@ family <- name <- path <- NULL - # check for Whitney - all_fonts <- systemfonts::system_fonts() - whitney_core <- c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold") - assign("use_whitney", - length(all_fonts$name[all_fonts$name %in% whitney_core]) >= 3, - envir = cmapplot_globals) + # if font registry already contains whitney core, set use_whitney == TRUE + check_for_whitney_core(set_global = TRUE) + + # else, register all whitney fonts in systemfonts. Then, if font registry + # contains whitney core, set use_whitney == TRUE + # + # (This is necessary because R looks up font by "family" with only basic + # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible + # by default. Font registration allows us to use the font's "name" as it's + # "family" so R can identify it.) + if(!get("use_whitney", envir = cmapplot_globals)){ + + whitney_fonts <- systemfonts::system_fonts() %>% + dplyr::filter(family == "Whitney") %>% + dplyr::select(name, path) + + purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) + + check_for_whitney_core(set_global = TRUE) + } + + # else, if not on Windows, check for /Library/Fonts directory. + # register all Whitney fonts in this folder. + # If font registry contains whitney core, set use_whitney == TRUE + if(!get("use_whitney", envir = cmapplot_globals) & .Platform$OS.type != "windows"){ - # If on a Mac, and !use_whitney, attempt to register from user's fonts folder - ## SHOULD THIS BE CHANGED TO ONLY IMPACT THE VM? SUCH AS USER == "runner"??? - if(.Platform$OS.type != "windows" & !get("use_whitney", envir = cmapplot_globals)){ - # attempt to register fonts in user's fonts folder - ## SHOULD THIS BE CHANGED TO ONLY WHITNEY FONTS? user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - user_font_names <- sub("-Adv.otf$", "", list.files(user_dir)) - user_font_paths <- list.files(user_dir, full.names = TRUE) - purrr::walk2(user_font_names, user_font_paths, systemfonts::register_font) - - registry_fonts <- systemfonts::registry_fonts() - message(length(registry_fonts$family[registry_fonts$family %in% whitney_core])) ## temp - assign("use_whitney", - length(registry_fonts$family[registry_fonts$family %in% whitney_core]) >= 3, - envir = cmapplot_globals) + + if(dir.exists(user_dir)){ + whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% + as.data.frame() %>% + rlang::set_names("path") %>% + dplyr::filter(stringr::str_detect(path, "Whitney")) %>% # Will error for username of "Whitney" + dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) + + purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) + + check_for_whitney_core(set_global = TRUE) + } } # Update font names diff --git a/R/utilities.R b/R/utilities.R index 5dc3b24d..b123172a 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -97,3 +97,29 @@ gg_lwd_convert <- function(value, unit = "bigpts") { value_out / .lwd ) } + + +#' Check for necessary Whitney fonts in systemfonts registry +#' +#' Invisibly returns TRUE or FALSE based on whether the three used Whitney fonts +#' are available in the systemfonts registry. +#' +#' @param set_global sets cmapplot_globals$use_whitney based on results +#' +#' @noRd +check_for_whitney_core <- function(set_global = FALSE){ + + whitney_core <- c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold") + + registry_fonts <- systemfonts::registry_fonts() + + whitney_core_present <- nrow(registry_fonts[registry_fonts$family %in% whitney_core,]) >= 3 + + if(set_global){ + assign("use_whitney", + whitney_core_present, + envir = cmapplot_globals) + } + + invisible(whitney_core_present) +} From b62472b50c8f794365078c33658bda607f8d5405 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 19 Apr 2021 01:46:44 -0500 Subject: [PATCH 54/83] clean up vignette testing --- vignettes/finalize.Rmd | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 382b7c67..84520827 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteEncoding{UTF-8} --- -```{r setup} +```{r setup, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", @@ -43,8 +43,6 @@ p <- ggplot(data = df, nudge_x = 0.5) + coord_cartesian(clip = "off") + theme_cmap() - -systemfonts::registry_fonts() ``` `finalize_plot()` will place a ggplot into a frame defined by CMAP design standards. It will align your title and caption to the left, add a horizontal line on top, and make other adjustments. It can show you the final plot and/or export it as a raster or vector file. This function will not apply CMAP design standards to the plot itself; use `theme_cmap()` for that. From 6c3e4ac85a4d699f6f0d9da33534d5fbbed573c9 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 19 Apr 2021 13:07:18 -0500 Subject: [PATCH 55/83] update pkgdown GHAs --- .github/workflows/pkgdown.yaml | 14 +++++++++----- .github/workflows/pkgdown_test.yaml | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index fa4decf0..c73f5d03 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -56,11 +56,15 @@ jobs: install.packages("pkgdown") shell: Rscript {0} - - name: Check Whitney availability + - name: Check Whitney availability in R run: | - message(paste(sysfonts::font_paths(), collapse = "\n")) - all_fonts <- sysfonts::font_files() - message(paste(all_fonts[all_fonts$family %in% c("Whitney Medium", "Whitney Book", "Whitney Semibold") & all_fonts$face=="Regular", "file"], collapse = "\n")) + all_fonts <- systemfonts::system_fonts() + message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") + message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) + user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") + library_fonts <- list.files(user_dir) + message(paste0("WHITNEY FONTS IN ", user_dir, " (MUST BE REGISTERED):")) + message(paste(library_fonts[grepl("^Whitney", library_fonts)], collapse = "\n")) shell: Rscript {0} - name: Install package @@ -70,4 +74,4 @@ jobs: run: | git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE)' + Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index a5a72b11..8bc28cb3 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -62,8 +62,9 @@ jobs: message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - message(paste0("CONTENTS OF ", user_dir, " (MUST BE REGISTERED):")) - message(paste(list.files(user_dir), collapse = "\n")) + library_fonts <- list.files(user_dir) + message(paste0("WHITNEY FONTS IN ", user_dir, " (MUST BE REGISTERED):")) + message(paste(library_fonts[grepl("^Whitney", library_fonts)], collapse = "\n")) shell: Rscript {0} - name: Install package From 90803ab7a73ba1744eff635c233e1fc73fc1fcc5 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 19 Apr 2021 13:25:21 -0500 Subject: [PATCH 56/83] adjust location of preferred font names --- R/cmapplot.R | 6 +++--- R/cmapplot_globals.R | 7 +++++++ R/utilities.R | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 0cc8e781..930ce71d 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -66,9 +66,9 @@ # Update font names if(get("use_whitney", envir = cmapplot_globals)){ assign("font", - list(strong = list(family = "Whitney-Semibold", face = "plain"), - regular = list(family = "Whitney-Medium", face = "plain"), - light = list(family = "Whitney-Book", face = "plain")), + list(strong = list(family = cmapplot_globals$preferred_font$strong, face = "plain"), + regular = list(family = cmapplot_globals$preferred_font$regular, face = "plain"), + light = list(family = cmapplot_globals$preferred_font$light, face = "plain")), envir = cmapplot_globals) } diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 85df09e4..0a65ef16 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -1,6 +1,13 @@ # Initialize environment for cmapplot global variables cmapplot_globals <- new.env(parent = emptyenv()) +# Establish names of preferred fonts +cmapplot_globals$preferred_font <- list( + strong = "Whitney-Semibold", + regular = "Whitney-Medium", + light = "Whitney-Book" +) + # Set up default font handling # (Note: overridden by .onLoad() if Whitney is available) cmapplot_globals$use_whitney <- FALSE diff --git a/R/utilities.R b/R/utilities.R index b123172a..c3f50254 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -109,11 +109,11 @@ gg_lwd_convert <- function(value, unit = "bigpts") { #' @noRd check_for_whitney_core <- function(set_global = FALSE){ - whitney_core <- c("Whitney-Medium", "Whitney-Book", "Whitney-Semibold") - registry_fonts <- systemfonts::registry_fonts() - whitney_core_present <- nrow(registry_fonts[registry_fonts$family %in% whitney_core,]) >= 3 + whitney_core_present <- nrow( + registry_fonts[registry_fonts$family %in% cmapplot_globals$preferred_font,] + ) >= 3 if(set_global){ assign("use_whitney", From 5ff89ba5fbe2b002dd8bbf2da6765a58d3fbc4be Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Wed, 21 Apr 2021 10:04:47 -0500 Subject: [PATCH 57/83] Minor tweaks --- .github/workflows/pkgdown_test.yaml | 1 - R/cmapplot.R | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 8bc28cb3..9d8547cd 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -70,7 +70,6 @@ jobs: - name: Install package run: R CMD INSTALL . - - name: Deploy package run: | git config --local user.email "actions@github.com" diff --git a/R/cmapplot.R b/R/cmapplot.R index 930ce71d..efbc34ae 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -22,15 +22,15 @@ family <- name <- path <- NULL - # if font registry already contains whitney core, set use_whitney == TRUE + # If font registry already contains whitney core, set use_whitney == TRUE check_for_whitney_core(set_global = TRUE) - # else, register all whitney fonts in systemfonts. Then, if font registry - # contains whitney core, set use_whitney == TRUE + # Else, register all whitney fonts in systemfonts. Then, if font registry + # contains whitney core, set use_whitney == TRUE. # # (This is necessary because R looks up font by "family" with only basic # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible - # by default. Font registration allows us to use the font's "name" as it's + # by default. Font registration allows us to use the font's "name" as its # "family" so R can identify it.) if(!get("use_whitney", envir = cmapplot_globals)){ @@ -43,8 +43,8 @@ check_for_whitney_core(set_global = TRUE) } - # else, if not on Windows, check for /Library/Fonts directory. - # register all Whitney fonts in this folder. + # Else, if not on Windows, check for ~/Library/Fonts directory. + # Register all Whitney fonts in this folder. # If font registry contains whitney core, set use_whitney == TRUE if(!get("use_whitney", envir = cmapplot_globals) & .Platform$OS.type != "windows"){ @@ -54,7 +54,7 @@ whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% as.data.frame() %>% rlang::set_names("path") %>% - dplyr::filter(stringr::str_detect(path, "Whitney")) %>% # Will error for username of "Whitney" + dplyr::filter(stringr::str_detect(path, "Whitney-")) %>% # Hope "Whitney-" is not in username! dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) From bc4adb23bf3abfd1bbb6cd197826c8170ed2774b Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 01:31:28 -0500 Subject: [PATCH 58/83] custom registration --- R/cmapplot.R | 57 ++++++++++++++++++++++++++++---------------- R/cmapplot_globals.R | 6 ++--- R/utilities.R | 24 +++++++++++++++---- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index efbc34ae..ecdc518e 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -23,44 +23,61 @@ family <- name <- path <- NULL # If font registry already contains whitney core, set use_whitney == TRUE - check_for_whitney_core(set_global = TRUE) + check_for_fonts(set_global = TRUE) - # Else, register all whitney fonts in systemfonts. Then, if font registry - # contains whitney core, set use_whitney == TRUE. + # Else, Find and register necessary whitney varients using systemfonts (or, + # alternatively, find them manually in ~/Library/Fonts). Then, if font + # registry contains whitney core, set use_whitney == TRUE. # # (This is necessary because R looks up font by "family" with only basic # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible - # by default. Font registration allows us to use the font's "name" as its - # "family" so R can identify it.) + # by default.) if(!get("use_whitney", envir = cmapplot_globals)){ whitney_fonts <- systemfonts::system_fonts() %>% dplyr::filter(family == "Whitney") %>% dplyr::select(name, path) - purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) - - check_for_whitney_core(set_global = TRUE) - } - - # Else, if not on Windows, check for ~/Library/Fonts directory. - # Register all Whitney fonts in this folder. - # If font registry contains whitney core, set use_whitney == TRUE - if(!get("use_whitney", envir = cmapplot_globals) & .Platform$OS.type != "windows"){ - + # On some OSX systems (e.g. pkgdown GHA VM) system_fonts() cannot find fonts + # installed in the user fonts directory. In any case where system_fonts() + # sees no Whitney fonts, if `user_dir` exists it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - - if(dir.exists(user_dir)){ + if(nrow(whitney_fonts == 0) & dir.exists(user_dir)){ whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% as.data.frame() %>% rlang::set_names("path") %>% dplyr::filter(stringr::str_detect(path, "Whitney-")) %>% # Hope "Whitney-" is not in username! dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) + } - purrr::walk2(whitney_fonts$name, whitney_fonts$path, systemfonts::register_font) + # register preferred strong font (Whitney Semibold), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$strong, + plain = find_path("Whitney-Semibold", whitney_fonts), + bold = find_path("Whitney-Black", whitney_fonts), + italic = find_path("Whitney-SemiboldItalic", whitney_fonts), + bolditalic = find_path("Whitney-BlackItalic", whitney_fonts) + ) - check_for_whitney_core(set_global = TRUE) - } + # register preferred regular font (Whitney Medium), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$regular, + plain = find_path("Whitney-Medium", whitney_fonts), + bold = find_path("Whitney-Bold", whitney_fonts), + italic = find_path("Whitney-MediumItalic", whitney_fonts), + bolditalic = find_path("Whitney-BoldItalic", whitney_fonts) + ) + + # register preferred light font (Whitney Book), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$light, + plain = find_path("Whitney-Book", whitney_fonts), + bold = find_path("Whitney-Semibold", whitney_fonts), + italic = find_path("Whitney-BookItalic", whitney_fonts), + bolditalic = find_path("Whitney-SemiboldItalic", whitney_fonts) + ) + + check_for_fonts(set_global = TRUE) } # Update font names diff --git a/R/cmapplot_globals.R b/R/cmapplot_globals.R index 0a65ef16..a86f2c3e 100644 --- a/R/cmapplot_globals.R +++ b/R/cmapplot_globals.R @@ -3,9 +3,9 @@ cmapplot_globals <- new.env(parent = emptyenv()) # Establish names of preferred fonts cmapplot_globals$preferred_font <- list( - strong = "Whitney-Semibold", - regular = "Whitney-Medium", - light = "Whitney-Book" + strong = "Whitney Semibold", + regular = "Whitney Medium", + light = "Whitney Book" ) # Set up default font handling diff --git a/R/utilities.R b/R/utilities.R index c3f50254..e88c070c 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -107,19 +107,35 @@ gg_lwd_convert <- function(value, unit = "bigpts") { #' @param set_global sets cmapplot_globals$use_whitney based on results #' #' @noRd -check_for_whitney_core <- function(set_global = FALSE){ +check_for_fonts <- function(set_global = FALSE){ registry_fonts <- systemfonts::registry_fonts() - whitney_core_present <- nrow( + fonts_present <- nrow( registry_fonts[registry_fonts$family %in% cmapplot_globals$preferred_font,] ) >= 3 if(set_global){ assign("use_whitney", - whitney_core_present, + fonts_present, envir = cmapplot_globals) } - invisible(whitney_core_present) + invisible(fonts_present) +} + +#' Find a "path" using a "name" +#' +#' Taking a dataframe that has columns "name" and "path", search for one +#' specific name and, if a perfect match is found, return it's "path". +#' +#' @noRd +find_path <- function(query, df){ + df <- dplyr::filter(df, stringr::str_detect(name, paste0("^", query, "$"))) + + if(nrow(df) == 1){ + return(df[[1,"path"]]) + } else { + stop("Font not found", call. = FALSE) + } } From 233773a601548e8fd0cb31c7a3ac07875b53d8b8 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 01:37:56 -0500 Subject: [PATCH 59/83] test message --- R/cmapplot.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/cmapplot.R b/R/cmapplot.R index ecdc518e..a5a94d52 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -48,6 +48,8 @@ rlang::set_names("path") %>% dplyr::filter(stringr::str_detect(path, "Whitney-")) %>% # Hope "Whitney-" is not in username! dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) + + message(paste(whitney_fonts, collapse = "\n")) } # register preferred strong font (Whitney Semibold), with variants From 5ba8cded31d52382330af7870965ca4fd58813a3 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 01:41:37 -0500 Subject: [PATCH 60/83] new check --- R/cmapplot.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/cmapplot.R b/R/cmapplot.R index a5a94d52..4ef19139 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -33,6 +33,8 @@ # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible # by default.) if(!get("use_whitney", envir = cmapplot_globals)){ + packageStartupMessage("Attempting to register Whitney fonts...") + message("Attempting to register Whitney fonts...") whitney_fonts <- systemfonts::system_fonts() %>% dplyr::filter(family == "Whitney") %>% From cface8d6b043ffb47db03ef25eb79b1f0c2c720a Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 01:46:31 -0500 Subject: [PATCH 61/83] new check --- R/cmapplot.R | 3 --- R/utilities.R | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 4ef19139..1206007e 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -33,9 +33,6 @@ # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible # by default.) if(!get("use_whitney", envir = cmapplot_globals)){ - packageStartupMessage("Attempting to register Whitney fonts...") - message("Attempting to register Whitney fonts...") - whitney_fonts <- systemfonts::system_fonts() %>% dplyr::filter(family == "Whitney") %>% dplyr::select(name, path) diff --git a/R/utilities.R b/R/utilities.R index e88c070c..8c22ee20 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -136,6 +136,6 @@ find_path <- function(query, df){ if(nrow(df) == 1){ return(df[[1,"path"]]) } else { - stop("Font not found", call. = FALSE) + stop(paste0("Font '", query, "' not found"), call. = FALSE) } } From c76adff69c2dcc2b501b71984d2a1b0541c0e63e Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 01:59:21 -0500 Subject: [PATCH 62/83] new check --- R/cmapplot.R | 2 -- R/utilities.R | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 1206007e..87661cbc 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -47,8 +47,6 @@ rlang::set_names("path") %>% dplyr::filter(stringr::str_detect(path, "Whitney-")) %>% # Hope "Whitney-" is not in username! dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) - - message(paste(whitney_fonts, collapse = "\n")) } # register preferred strong font (Whitney Semibold), with variants diff --git a/R/utilities.R b/R/utilities.R index 8c22ee20..cf79c7bc 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -131,11 +131,12 @@ check_for_fonts <- function(set_global = FALSE){ #' #' @noRd find_path <- function(query, df){ - df <- dplyr::filter(df, stringr::str_detect(name, paste0("^", query, "$"))) + query <- paste0("^", query, "$") + df <- dplyr::filter(df, stringr::str_detect(name, query)) if(nrow(df) == 1){ return(df[[1,"path"]]) } else { - stop(paste0("Font '", query, "' not found"), call. = FALSE) + stop(paste0("Font '", query, "' not found. Query: ", query, ". nrow: ", nrow(df)), call. = FALSE) } } From ba44649d0c0405ba1cfecd80d7b085374d832b4c Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:03:11 -0500 Subject: [PATCH 63/83] more checkssss --- R/utilities.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index cf79c7bc..f732474a 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -131,12 +131,12 @@ check_for_fonts <- function(set_global = FALSE){ #' #' @noRd find_path <- function(query, df){ - query <- paste0("^", query, "$") - df <- dplyr::filter(df, stringr::str_detect(name, query)) + warning("test warning") + df2 <- dplyr::filter(df, stringr::str_detect(name, paste0("^", query, "$"))) - if(nrow(df) == 1){ - return(df[[1,"path"]]) + if(nrow(df2) == 1){ + return(df2[[1,"path"]]) } else { - stop(paste0("Font '", query, "' not found. Query: ", query, ". nrow: ", nrow(df)), call. = FALSE) + stop(paste0("Font '", query, "' not found. nrow before: ", nrow(df), ". nrow after: ", nrow(df2)), call. = FALSE) } } From 5546ff2d98c336f73df20a95e86a65c900d882f2 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:09:47 -0500 Subject: [PATCH 64/83] new checks --- R/cmapplot.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/cmapplot.R b/R/cmapplot.R index 87661cbc..13adc923 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -42,6 +42,7 @@ # sees no Whitney fonts, if `user_dir` exists it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") if(nrow(whitney_fonts == 0) & dir.exists(user_dir)){ + warning(paste("alternative search in", user_dir)) whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% as.data.frame() %>% rlang::set_names("path") %>% @@ -49,6 +50,8 @@ dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) } + warning(paste(whitney_fonts, collapse = "\n")) + # register preferred strong font (Whitney Semibold), with variants systemfonts::register_font( name = cmapplot_globals$preferred_font$strong, From ba1590add20755a7f52e2b7e456e99e64ac0fdb3 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:12:41 -0500 Subject: [PATCH 65/83] I think I found it! --- R/cmapplot.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 13adc923..24365161 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -41,7 +41,7 @@ # installed in the user fonts directory. In any case where system_fonts() # sees no Whitney fonts, if `user_dir` exists it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - if(nrow(whitney_fonts == 0) & dir.exists(user_dir)){ + if(nrow(whitney_fonts) == 0 & dir.exists(user_dir)){ warning(paste("alternative search in", user_dir)) whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% as.data.frame() %>% From 64e2ce86011dd123fc80011663aea06285267a0f Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:40:39 -0500 Subject: [PATCH 66/83] lets try this --- R/cmapplot.R | 50 +++++++++++++++++++++++++++----------------------- R/utilities.R | 38 ++++++++------------------------------ 2 files changed, 35 insertions(+), 53 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 24365161..7062b0f2 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -23,7 +23,14 @@ family <- name <- path <- NULL # If font registry already contains whitney core, set use_whitney == TRUE - check_for_fonts(set_global = TRUE) + fonts_present <- systemfonts::registry_fonts() %>% + dplyr::filter(family %in% cmapplot_globals$preferred_font) %>% + nrow() >= 12 + + assign("use_whitney", + fonts_present, + envir = cmapplot_globals) + # Else, Find and register necessary whitney varients using systemfonts (or, # alternatively, find them manually in ~/Library/Fonts). Then, if font @@ -33,50 +40,47 @@ # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible # by default.) if(!get("use_whitney", envir = cmapplot_globals)){ - whitney_fonts <- systemfonts::system_fonts() %>% + whitney_paths <- systemfonts::system_fonts() %>% dplyr::filter(family == "Whitney") %>% - dplyr::select(name, path) + .[["path"]] # On some OSX systems (e.g. pkgdown GHA VM) system_fonts() cannot find fonts # installed in the user fonts directory. In any case where system_fonts() - # sees no Whitney fonts, if `user_dir` exists it too is checked for fonts. + # sees no Whitney fonts, if `user_dir` exists, it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - if(nrow(whitney_fonts) == 0 & dir.exists(user_dir)){ + if(length(whitney_paths) == 0 & dir.exists(user_dir)){ warning(paste("alternative search in", user_dir)) - whitney_fonts <- list.files(user_dir, full.names = TRUE) %>% - as.data.frame() %>% - rlang::set_names("path") %>% - dplyr::filter(stringr::str_detect(path, "Whitney-")) %>% # Hope "Whitney-" is not in username! - dplyr::mutate(name = stringr::str_extract(path, "Whitney-[:alpha:]*(?=-Adv.otf$)")) + whitney_paths <- list.files(user_dir, full.names = TRUE) %>% + .[grepl("Whitney-", .)] } - warning(paste(whitney_fonts, collapse = "\n")) + warning(paste(whitney_paths, collapse = "\n")) # register preferred strong font (Whitney Semibold), with variants systemfonts::register_font( name = cmapplot_globals$preferred_font$strong, - plain = find_path("Whitney-Semibold", whitney_fonts), - bold = find_path("Whitney-Black", whitney_fonts), - italic = find_path("Whitney-SemiboldItalic", whitney_fonts), - bolditalic = find_path("Whitney-BlackItalic", whitney_fonts) + plain = find_path("Whitney-Semibold-Adv", whitney_paths), + bold = find_path("Whitney-Black-Adv", whitney_paths), + italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) ) # register preferred regular font (Whitney Medium), with variants systemfonts::register_font( name = cmapplot_globals$preferred_font$regular, - plain = find_path("Whitney-Medium", whitney_fonts), - bold = find_path("Whitney-Bold", whitney_fonts), - italic = find_path("Whitney-MediumItalic", whitney_fonts), - bolditalic = find_path("Whitney-BoldItalic", whitney_fonts) + plain = find_path("Whitney-Medium-Adv", whitney_paths), + bold = find_path("Whitney-Bold-Adv", whitney_paths), + italic = find_path("Whitney-MediumItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) ) # register preferred light font (Whitney Book), with variants systemfonts::register_font( name = cmapplot_globals$preferred_font$light, - plain = find_path("Whitney-Book", whitney_fonts), - bold = find_path("Whitney-Semibold", whitney_fonts), - italic = find_path("Whitney-BookItalic", whitney_fonts), - bolditalic = find_path("Whitney-SemiboldItalic", whitney_fonts) + plain = find_path("Whitney-Book-Adv", whitney_paths), + bold = find_path("Whitney-Semibold-Adv", whitney_paths), + italic = find_path("Whitney-BookItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) ) check_for_fonts(set_global = TRUE) diff --git a/R/utilities.R b/R/utilities.R index f732474a..259df1b1 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -99,30 +99,6 @@ gg_lwd_convert <- function(value, unit = "bigpts") { } -#' Check for necessary Whitney fonts in systemfonts registry -#' -#' Invisibly returns TRUE or FALSE based on whether the three used Whitney fonts -#' are available in the systemfonts registry. -#' -#' @param set_global sets cmapplot_globals$use_whitney based on results -#' -#' @noRd -check_for_fonts <- function(set_global = FALSE){ - - registry_fonts <- systemfonts::registry_fonts() - - fonts_present <- nrow( - registry_fonts[registry_fonts$family %in% cmapplot_globals$preferred_font,] - ) >= 3 - - if(set_global){ - assign("use_whitney", - fonts_present, - envir = cmapplot_globals) - } - - invisible(fonts_present) -} #' Find a "path" using a "name" #' @@ -130,13 +106,15 @@ check_for_fonts <- function(set_global = FALSE){ #' specific name and, if a perfect match is found, return it's "path". #' #' @noRd -find_path <- function(query, df){ - warning("test warning") - df2 <- dplyr::filter(df, stringr::str_detect(name, paste0("^", query, "$"))) +find_path <- function(query, vector){ + result <- vector[grepl(paste0("(\\\\|/)", query, ".[ot]tf$"), vector)] - if(nrow(df2) == 1){ - return(df2[[1,"path"]]) + if(length(result) == 1){ + return(result) } else { - stop(paste0("Font '", query, "' not found. nrow before: ", nrow(df), ". nrow after: ", nrow(df2)), call. = FALSE) + stop( + paste0("Font '", query, "' not found. search vector:\n", + paste(vector, collapse = "\n")), + call. = FALSE) } } From 0fe7e7fdf7f0d017f514a87f33e98a2aacc81f00 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:44:38 -0500 Subject: [PATCH 67/83] famous last words --- R/cmapplot.R | 62 +++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 7062b0f2..f11c8b74 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -49,41 +49,43 @@ # sees no Whitney fonts, if `user_dir` exists, it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") if(length(whitney_paths) == 0 & dir.exists(user_dir)){ - warning(paste("alternative search in", user_dir)) whitney_paths <- list.files(user_dir, full.names = TRUE) %>% .[grepl("Whitney-", .)] } - warning(paste(whitney_paths, collapse = "\n")) - # register preferred strong font (Whitney Semibold), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$strong, - plain = find_path("Whitney-Semibold-Adv", whitney_paths), - bold = find_path("Whitney-Black-Adv", whitney_paths), - italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) - ) - - # register preferred regular font (Whitney Medium), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$regular, - plain = find_path("Whitney-Medium-Adv", whitney_paths), - bold = find_path("Whitney-Bold-Adv", whitney_paths), - italic = find_path("Whitney-MediumItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) - ) - - # register preferred light font (Whitney Book), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$light, - plain = find_path("Whitney-Book-Adv", whitney_paths), - bold = find_path("Whitney-Semibold-Adv", whitney_paths), - italic = find_path("Whitney-BookItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) - ) - - check_for_fonts(set_global = TRUE) + if(length(whitney_paths >= 12)){ + # register preferred strong font (Whitney Semibold), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$strong, + plain = find_path("Whitney-Semibold-Adv", whitney_paths), + bold = find_path("Whitney-Black-Adv", whitney_paths), + italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) + ) + + # register preferred regular font (Whitney Medium), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$regular, + plain = find_path("Whitney-Medium-Adv", whitney_paths), + bold = find_path("Whitney-Bold-Adv", whitney_paths), + italic = find_path("Whitney-MediumItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) + ) + + # register preferred light font (Whitney Book), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$light, + plain = find_path("Whitney-Book-Adv", whitney_paths), + bold = find_path("Whitney-Semibold-Adv", whitney_paths), + italic = find_path("Whitney-BookItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) + ) + + assign("use_whitney", + fonts_present, + envir = cmapplot_globals) + } } # Update font names From c698e0f1bbfd46a6ce9052c6939d28365a9ce657 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Fri, 23 Apr 2021 02:49:42 -0500 Subject: [PATCH 68/83] whoops --- R/cmapplot.R | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index f11c8b74..16efe632 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -22,7 +22,7 @@ family <- name <- path <- NULL - # If font registry already contains whitney core, set use_whitney == TRUE + # If font registry already contains Whitney core, set use_whitney == TRUE fonts_present <- systemfonts::registry_fonts() %>% dplyr::filter(family %in% cmapplot_globals$preferred_font) %>% nrow() >= 12 @@ -32,13 +32,9 @@ envir = cmapplot_globals) - # Else, Find and register necessary whitney varients using systemfonts (or, + # Else, Find and register necessary Whitney variants using systemfonts (or, # alternatively, find them manually in ~/Library/Fonts). Then, if font - # registry contains whitney core, set use_whitney == TRUE. - # - # (This is necessary because R looks up font by "family" with only basic - # variation (bold, italic, etc), so fonts like "Whitney-Book" are inaccessible - # by default.) + # registry contains Whitney core, set use_whitney == TRUE. if(!get("use_whitney", envir = cmapplot_globals)){ whitney_paths <- systemfonts::system_fonts() %>% dplyr::filter(family == "Whitney") %>% @@ -53,7 +49,7 @@ .[grepl("Whitney-", .)] } - + # If all Whitney fonts have been found... if(length(whitney_paths >= 12)){ # register preferred strong font (Whitney Semibold), with variants systemfonts::register_font( @@ -83,7 +79,7 @@ ) assign("use_whitney", - fonts_present, + TRUE, envir = cmapplot_globals) } } From c56726be01f06a1fb5c3a370d3312e84558d028e Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 25 Apr 2021 14:13:40 -0500 Subject: [PATCH 69/83] check() works --- R/cmapplot.R | 100 ++++++++++++++++++++---------------- R/utilities.R | 9 ++-- man/get_cmapplot_globals.Rd | 2 +- vignettes/finalize.Rmd | 4 +- 4 files changed, 63 insertions(+), 52 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 16efe632..da49a970 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -36,51 +36,60 @@ # alternatively, find them manually in ~/Library/Fonts). Then, if font # registry contains Whitney core, set use_whitney == TRUE. if(!get("use_whitney", envir = cmapplot_globals)){ - whitney_paths <- systemfonts::system_fonts() %>% - dplyr::filter(family == "Whitney") %>% - .[["path"]] + whitney_paths <- dplyr::filter(systemfonts::system_fonts(), family == "Whitney") + whitney_paths <- whitney_paths[["path"]] # On some OSX systems (e.g. pkgdown GHA VM) system_fonts() cannot find fonts # installed in the user fonts directory. In any case where system_fonts() # sees no Whitney fonts, if `user_dir` exists, it too is checked for fonts. user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") if(length(whitney_paths) == 0 & dir.exists(user_dir)){ - whitney_paths <- list.files(user_dir, full.names = TRUE) %>% - .[grepl("Whitney-", .)] + whitney_paths <- list.files(user_dir, full.names = TRUE) + whitney_paths <- grep("Whitney-", whitney_paths) } - # If all Whitney fonts have been found... + # If all Whitney fonts have been found, attempt to register preferred + # fonts. If any registration fails, the try object should fail before + # `use_whitney` is set to TRUE. if(length(whitney_paths >= 12)){ - # register preferred strong font (Whitney Semibold), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$strong, - plain = find_path("Whitney-Semibold-Adv", whitney_paths), - bold = find_path("Whitney-Black-Adv", whitney_paths), - italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) - ) - - # register preferred regular font (Whitney Medium), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$regular, - plain = find_path("Whitney-Medium-Adv", whitney_paths), - bold = find_path("Whitney-Bold-Adv", whitney_paths), - italic = find_path("Whitney-MediumItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) - ) - - # register preferred light font (Whitney Book), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$light, - plain = find_path("Whitney-Book-Adv", whitney_paths), - bold = find_path("Whitney-Semibold-Adv", whitney_paths), - italic = find_path("Whitney-BookItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) - ) - - assign("use_whitney", - TRUE, - envir = cmapplot_globals) + try({ + + # register preferred strong font (Whitney Semibold), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$strong, + plain = find_path("Whitney-Semibold-Adv", whitney_paths), + bold = find_path("Whitney-Black-Adv", whitney_paths), + italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) + ) + + # register preferred regular font (Whitney Medium), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$regular, + plain = find_path("Whitney-Medium-Adv", whitney_paths), + bold = find_path("Whitney-Bold-Adv", whitney_paths), + italic = find_path("Whitney-MediumItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) + ) + + # register preferred light font (Whitney Book), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$light, + plain = find_path("Whitney-Book-Adv", whitney_paths), + bold = find_path("Whitney-Semibold-Adv", whitney_paths), + italic = find_path("Whitney-BookItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) + ) + + packageStartupMessage(paste0( + "cmapplot has registered the following fonts for use in this R session:\n ", + paste(cmapplot_globals$preferred_font, collapse = ", ") + )) + + assign("use_whitney", + TRUE, + envir = cmapplot_globals) + }) } } @@ -91,8 +100,18 @@ regular = list(family = cmapplot_globals$preferred_font$regular, face = "plain"), light = list(family = cmapplot_globals$preferred_font$light, face = "plain")), envir = cmapplot_globals) + } else { + packageStartupMessage( + "cmapplot cannot locate Whitney fonts, so CMAP themes will use your default sans-serif font" + ) } + # if (VERSION >= 1.4){ + # check ragg, set ragg, notify + # } else { + # message about need to update rstudio + # } + # Load CMAP preferred default.aes (can't be done until fonts are specified) assign("default_aes_cmap", init_cmap_default_aes(), @@ -103,12 +122,3 @@ fetch_current_default_aes(), envir = cmapplot_globals) } - - -.onAttach <- function(...){ - if(!get("use_whitney", envir = cmapplot_globals)){ - packageStartupMessage( - "WARNING: Whitney was not found on this machine, so CMAP theme will use your default sans-serif font" - ) - } -} diff --git a/R/utilities.R b/R/utilities.R index 259df1b1..36e41771 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -105,16 +105,17 @@ gg_lwd_convert <- function(value, unit = "bigpts") { #' Taking a dataframe that has columns "name" and "path", search for one #' specific name and, if a perfect match is found, return it's "path". #' +#' @param filename the complete file name, less a .otf or .ttf extension. +#' #' @noRd -find_path <- function(query, vector){ - result <- vector[grepl(paste0("(\\\\|/)", query, ".[ot]tf$"), vector)] +find_path <- function(filename, paths){ + result <- paths[grepl(paste0("(\\\\|/)", filename, ".[ot]tf$"), paths)] if(length(result) == 1){ return(result) } else { stop( - paste0("Font '", query, "' not found. search vector:\n", - paste(vector, collapse = "\n")), + paste0("Font '", filename, "' not found."), call. = FALSE) } } diff --git a/man/get_cmapplot_globals.Rd b/man/get_cmapplot_globals.Rd index e9783544..e39f8f93 100644 --- a/man/get_cmapplot_globals.Rd +++ b/man/get_cmapplot_globals.Rd @@ -77,7 +77,7 @@ helper functions described here provide the user access if needed. caption). \strong{(F)} \item \code{margin_sidebar_l}: The margin between the left edge of the image and the title and caption, when the sidebar exists. Deducted from \code{title_width}. \strong{(F)} \item \code{margin_plot_l}: - The margin between the left edge of the plot and the sidebar. \strong{(F)} + The margin between the left edge of the plot and the sodebar. \strong{(F)} \item \code{margin_plot_r}: The margin between the right edge of the plot and the edge of the image. \strong{(F)} \item \code{margin_panel_r}: Padding between the plot and its right-hand drawing extent. Override this based on diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 84520827..a2cbe0a6 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -139,8 +139,8 @@ The title and caption blocks take HTML formatting tags, which you can use to man # A finalized line graph, with text tweaks finalize_plot(plot = p, title = "Annual
unlinked passenger trips
(in millions)", - caption = "Source: Chicago Metropolitan Agency for Planning - analysis of Regional Transportation Authority data") + caption = "Source: Chicago Metropolitan Agency for Planning + analysis of Regional Transportation Authority data") ``` ## Advanced customization From 50a921d701e1f000063330f4abe5d8d21c51d032 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 25 Apr 2021 14:40:21 -0500 Subject: [PATCH 70/83] require agg for rstudio graphics --- DESCRIPTION | 1 + NAMESPACE | 1 + R/cmapplot.R | 29 +++++++++++++++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8159c1f0..8facfcb2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -50,6 +50,7 @@ Imports: purrr, ragg, rlang, + rstudioapi, scales, stringr, systemfonts diff --git a/NAMESPACE b/NAMESPACE index dd94c2c8..7c85bff0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,6 +40,7 @@ import(graphics) import(grid) import(gridtext) import(rlang) +import(rstudioapi) import(scales) import(systemfonts) importFrom(generics,intersect) diff --git a/R/cmapplot.R b/R/cmapplot.R index da49a970..3c8750e0 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -17,7 +17,10 @@ "_PACKAGE" -# Update fonts based on system -- *must* be done with .onLoad() +#' Update fonts based on system -- *must* be done with .onLoad() +#' +#' @noRd +#' @import rstudioapi .onLoad <- function(...) { family <- name <- path <- NULL @@ -93,25 +96,35 @@ } } - # Update font names + # If Whitney is available... if(get("use_whitney", envir = cmapplot_globals)){ + # ... Update font names assign("font", list(strong = list(family = cmapplot_globals$preferred_font$strong, face = "plain"), regular = list(family = cmapplot_globals$preferred_font$regular, face = "plain"), light = list(family = cmapplot_globals$preferred_font$light, face = "plain")), envir = cmapplot_globals) + + # ... and check on rstudio graphics + if (rstudioapi::isAvailable()){ + if(rstudioapi::getVersion() > 1.4){ + if(getOption("RStudioGD.backend") != "ragg"){ + options(RStudioGD.backend = "ragg") + packageStartupMessage("cmapplot has set RStudio graphics to `ragg`.") + } + } else { + packageStartupMessage(paste( + "cmapplot requires RStudio v1.4 or greater to use Whitney fonts", + "in the R plots window. ")) + } + } + # Otherwise, notify user } else { packageStartupMessage( "cmapplot cannot locate Whitney fonts, so CMAP themes will use your default sans-serif font" ) } - # if (VERSION >= 1.4){ - # check ragg, set ragg, notify - # } else { - # message about need to update rstudio - # } - # Load CMAP preferred default.aes (can't be done until fonts are specified) assign("default_aes_cmap", init_cmap_default_aes(), From 9daa57cd868502e668e7d8266bce8b5abadbc989 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 25 Apr 2021 14:45:42 -0500 Subject: [PATCH 71/83] typo in grep --- R/cmapplot.R | 4 ++-- R/utilities.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 3c8750e0..3b726321 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -48,7 +48,7 @@ user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") if(length(whitney_paths) == 0 & dir.exists(user_dir)){ whitney_paths <- list.files(user_dir, full.names = TRUE) - whitney_paths <- grep("Whitney-", whitney_paths) + whitney_paths <- grep("Whitney-", whitney_paths, value = TRUE) } # If all Whitney fonts have been found, attempt to register preferred @@ -115,7 +115,7 @@ } else { packageStartupMessage(paste( "cmapplot requires RStudio v1.4 or greater to use Whitney fonts", - "in the R plots window. ")) + "in the R plots window. Please upgrade RStudio.")) } } # Otherwise, notify user diff --git a/R/utilities.R b/R/utilities.R index 36e41771..03681155 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -109,7 +109,7 @@ gg_lwd_convert <- function(value, unit = "bigpts") { #' #' @noRd find_path <- function(filename, paths){ - result <- paths[grepl(paste0("(\\\\|/)", filename, ".[ot]tf$"), paths)] + result <- grep(paste0("(\\\\|/)", filename, ".[ot]tf$"), paths, value = TRUE) if(length(result) == 1){ return(result) From 53c8627ca585869f78f844140ab2dcef9e2af0cf Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 25 Apr 2021 14:57:07 -0500 Subject: [PATCH 72/83] documentation updates --- R/utilities.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 03681155..62c58c35 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -100,12 +100,13 @@ gg_lwd_convert <- function(value, unit = "bigpts") { -#' Find a "path" using a "name" +#' Identify correct font path based on filename #' -#' Taking a dataframe that has columns "name" and "path", search for one -#' specific name and, if a perfect match is found, return it's "path". +#' Taking a list of font paths, search for a specific filename. If a perfect +#' match is found, return that path. #' #' @param filename the complete file name, less a .otf or .ttf extension. +#' @param path a vector of filepaths #' #' @noRd find_path <- function(filename, paths){ From 8ce6f93a9219a050ffdcf0eb0fbc6498910488d4 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 25 Apr 2021 15:35:06 -0500 Subject: [PATCH 73/83] clearer messages looks like options() isn't sticky across R sessions, which seems strange to me. --- R/cmapplot.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 3b726321..9eef3405 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -85,7 +85,7 @@ ) packageStartupMessage(paste0( - "cmapplot has registered the following fonts for use in this R session:\n ", + "cmapplot has registered the following fonts for use in this R session:\n ", paste(cmapplot_globals$preferred_font, collapse = ", ") )) @@ -110,7 +110,11 @@ if(rstudioapi::getVersion() > 1.4){ if(getOption("RStudioGD.backend") != "ragg"){ options(RStudioGD.backend = "ragg") - packageStartupMessage("cmapplot has set RStudio graphics to `ragg`.") + packageStartupMessage(paste( + "cmapplot has set RStudio graphics to `ragg` for the current session.", + "You can make this change permanent:\n ", + "Tools > Global Options > General > Graphics > Graphics Device > Backend == 'AGG'." + )) } } else { packageStartupMessage(paste( @@ -121,7 +125,7 @@ # Otherwise, notify user } else { packageStartupMessage( - "cmapplot cannot locate Whitney fonts, so CMAP themes will use your default sans-serif font" + "cmapplot cannot locate Whitney fonts, so CMAP themes will use your default sans-serif font." ) } From 6e6ea4e4fc66efc16d3b0b0bce66300fd514f1c8 Mon Sep 17 00:00:00 2001 From: Matthew Stern <54633946+matthewstern@users.noreply.github.com> Date: Sat, 1 May 2021 15:41:47 -0500 Subject: [PATCH 74/83] simplify `try()` and clarify comments --- R/cmapplot.R | 84 ++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 9eef3405..0ec6c60e 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -51,48 +51,48 @@ whitney_paths <- grep("Whitney-", whitney_paths, value = TRUE) } - # If all Whitney fonts have been found, attempt to register preferred - # fonts. If any registration fails, the try object should fail before - # `use_whitney` is set to TRUE. - if(length(whitney_paths >= 12)){ - try({ - - # register preferred strong font (Whitney Semibold), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$strong, - plain = find_path("Whitney-Semibold-Adv", whitney_paths), - bold = find_path("Whitney-Black-Adv", whitney_paths), - italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) - ) - - # register preferred regular font (Whitney Medium), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$regular, - plain = find_path("Whitney-Medium-Adv", whitney_paths), - bold = find_path("Whitney-Bold-Adv", whitney_paths), - italic = find_path("Whitney-MediumItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) - ) - - # register preferred light font (Whitney Book), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$light, - plain = find_path("Whitney-Book-Adv", whitney_paths), - bold = find_path("Whitney-Semibold-Adv", whitney_paths), - italic = find_path("Whitney-BookItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) - ) - - packageStartupMessage(paste0( - "cmapplot has registered the following fonts for use in this R session:\n ", - paste(cmapplot_globals$preferred_font, collapse = ", ") - )) - - assign("use_whitney", - TRUE, - envir = cmapplot_globals) - }) + # Attempt to register preferred fonts using paths found above. The correct + # Whitney fonts may not be available (e.g. `whitney_paths` will have a length + # of 0 if no Whitney faces are located) - in this case, `find_path` will error + # and the try object will fail before `use_whitney` is set to TRUE. + try({ + + # register preferred strong font (Whitney Semibold), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$strong, + plain = find_path("Whitney-Semibold-Adv", whitney_paths), + bold = find_path("Whitney-Black-Adv", whitney_paths), + italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) + ) + + # register preferred regular font (Whitney Medium), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$regular, + plain = find_path("Whitney-Medium-Adv", whitney_paths), + bold = find_path("Whitney-Bold-Adv", whitney_paths), + italic = find_path("Whitney-MediumItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) + ) + + # register preferred light font (Whitney Book), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$light, + plain = find_path("Whitney-Book-Adv", whitney_paths), + bold = find_path("Whitney-Semibold-Adv", whitney_paths), + italic = find_path("Whitney-BookItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) + ) + + packageStartupMessage(paste0( + "cmapplot has registered the following fonts for use in this R session:\n ", + paste(cmapplot_globals$preferred_font, collapse = ", ") + )) + + assign("use_whitney", + TRUE, + envir = cmapplot_globals) + }) } } From 661667a04da0800c3d4d54f9cd8f6bae71b5c792 Mon Sep 17 00:00:00 2001 From: Matthew Stern <54633946+matthewstern@users.noreply.github.com> Date: Sat, 1 May 2021 15:53:26 -0500 Subject: [PATCH 75/83] typo --- R/cmapplot.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 0ec6c60e..2875a536 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -93,7 +93,6 @@ TRUE, envir = cmapplot_globals) }) - } } # If Whitney is available... From 840b1d52bd7212395e8f0d318b1e0c0306cffa98 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 2 May 2021 10:20:27 -0500 Subject: [PATCH 76/83] small tweaks --- R/finalize_plot.R | 20 -------------------- R/utilities.R | 21 +++++++++++++++++++++ vignettes/finalize.Rmd | 4 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/R/finalize_plot.R b/R/finalize_plot.R index b24906bd..debb832d 100644 --- a/R/finalize_plot.R +++ b/R/finalize_plot.R @@ -721,23 +721,3 @@ save_plot <- function(finished_graphic, ) } - - -#' Sub-fn to safely intepret grobHeight -#' -#' This returns the height of Grob in any real unit. -#' If the value passed in is null, it returns 0. -#' -#' @noRd -safe_grobHeight <- function(grob, unitTo = "bigpts", valueOnly = TRUE){ - - if(is.null(grob)){ - if(valueOnly){ - return(0) - } else { - return(unit(0, unitTo)) - } - } - - return(grid::convertHeight(grid::grobHeight(grob), unitTo, valueOnly)) -} diff --git a/R/utilities.R b/R/utilities.R index 62c58c35..fe75eee6 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -120,3 +120,24 @@ find_path <- function(filename, paths){ call. = FALSE) } } + + +#' Sub-fn to safely intepret grobHeight +#' +#' This returns the height of Grob in any real unit. +#' If the value passed in is null, it returns 0. +#' It is used in various places in `finalize_plot` +#' +#' @noRd +safe_grobHeight <- function(grob, unitTo = "bigpts", valueOnly = TRUE){ + + if(is.null(grob)){ + if(valueOnly){ + return(0) + } else { + return(unit(0, unitTo)) + } + } + + return(grid::convertHeight(grid::grobHeight(grob), unitTo, valueOnly)) +} diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index a2cbe0a6..8141939c 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -138,9 +138,9 @@ The title and caption blocks take HTML formatting tags, which you can use to man ```{r finalize5, message=FALSE} # A finalized line graph, with text tweaks finalize_plot(plot = p, - title = "Annual
unlinked passenger trips
(in millions)", + title = "Annual
unlinked passenger trips
(in millions)", caption = "Source: Chicago Metropolitan Agency for Planning - analysis of Regional Transportation Authority data") + analysis of Regional Transportation Authority data") ``` ## Advanced customization From c2c7b49225556bfa5df9b8a2ebfa80b97aef2ea2 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 2 May 2021 16:23:30 -0500 Subject: [PATCH 77/83] attempt at dynamic GHA workflow --- .github/workflows/pkgdown_test.yaml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index 9d8547cd..fdc4c147 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -2,7 +2,8 @@ # Based on . on: push: - branches: systemfonts + branches: master + pull_request: name: pkgdown_systemfonts_test @@ -52,6 +53,7 @@ jobs: - name: Install dependencies run: | + message() remotes::install_deps(dependencies = TRUE) install.packages("pkgdown") shell: Rscript {0} @@ -70,8 +72,18 @@ jobs: - name: Install package run: R CMD INSTALL . - - name: Deploy package + - name: Deploy packageto live branch + if: ${{ github.ref == 'refs/heads/main' }} run: | + echo "This is $GITHUB_REF. Deploying to 'gh-pages' branch." git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test2", clean = TRUE)' + Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' + + - name: Deploy package to test branch + if: ${{ github.ref != 'refs/heads/main' }} + run: | + echo "This is $GITHUB_REF. Deploying to 'gh-pages-test' branch." + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", clean = TRUE)' From e74c216d5e34c46c88685ab9dbca98d5f5777a96 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 2 May 2021 16:31:27 -0500 Subject: [PATCH 78/83] tweaks to GHA --- .github/workflows/pkgdown_test.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml index fdc4c147..2edb82cf 100644 --- a/.github/workflows/pkgdown_test.yaml +++ b/.github/workflows/pkgdown_test.yaml @@ -1,4 +1,5 @@ # Automatically rebuilds pkgdown website any time master branch is updated. +# Also builds pkgdown on "gh-pages-test" on commits to pull requests. # Based on . on: push: @@ -72,10 +73,10 @@ jobs: - name: Install package run: R CMD INSTALL . - - name: Deploy packageto live branch + - name: Deploy package to live branch if: ${{ github.ref == 'refs/heads/main' }} run: | - echo "This is $GITHUB_REF. Deploying to 'gh-pages' branch." + echo "This is $GITHUB_REF. Deploying to gh-pages branch." git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' @@ -83,7 +84,7 @@ jobs: - name: Deploy package to test branch if: ${{ github.ref != 'refs/heads/main' }} run: | - echo "This is $GITHUB_REF. Deploying to 'gh-pages-test' branch." + echo "This is $GITHUB_REF. Deploying to gh-pages-test branch." git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", clean = TRUE)' From 8204056d9b75c0aec038a36eba9139b5e87d24c9 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Sun, 2 May 2021 16:41:15 -0500 Subject: [PATCH 79/83] Remove pkgtown test workflow, update main workflow primary pkgdown workflow now deploys to gh-pages-test on any open PR update, and *should* deploy to gh-pages on push to master. --- .github/workflows/pkgdown.yaml | 15 ++++- .github/workflows/pkgdown_test.yaml | 90 ----------------------------- 2 files changed, 14 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/pkgdown_test.yaml diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index c73f5d03..ceed61f1 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -1,8 +1,11 @@ # Automatically rebuilds pkgdown website any time master branch is updated. +# Also builds pkgdown on "gh-pages-test" on commits to pull requests. # Based on . +# Conditional based on . on: push: branches: master + pull_request: name: pkgdown @@ -70,8 +73,18 @@ jobs: - name: Install package run: R CMD INSTALL . - - name: Deploy package + - name: Deploy package to live branch + if: ${{ github.ref == 'refs/heads/main' }} run: | + echo "This is $GITHUB_REF. Deploying to gh-pages branch." git config --local user.email "actions@github.com" git config --local user.name "GitHub Actions" Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' + + - name: Deploy package to test branch + if: ${{ github.ref != 'refs/heads/main' }} + run: | + echo "This is $GITHUB_REF. Deploying to gh-pages-test branch." + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", clean = TRUE)' diff --git a/.github/workflows/pkgdown_test.yaml b/.github/workflows/pkgdown_test.yaml deleted file mode 100644 index 2edb82cf..00000000 --- a/.github/workflows/pkgdown_test.yaml +++ /dev/null @@ -1,90 +0,0 @@ -# Automatically rebuilds pkgdown website any time master branch is updated. -# Also builds pkgdown on "gh-pages-test" on commits to pull requests. -# Based on . -on: - push: - branches: master - pull_request: - -name: pkgdown_systemfonts_test - -jobs: - pkgdown: - runs-on: macOS-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@master - - - uses: r-lib/actions/setup-pandoc@master - - - name: Checkout CMAP fonts repo - uses: actions/checkout@v2 - with: - repository: CMAP-REPOS/cmap-fonts - token: ${{ secrets.CMAP_REPO_FULL_ACCESS }} - path: cmap-fonts - - - name: Install CMAP fonts for R access - # Inspiration: https://gist.github.com/Kevin-Lee/328e9993d6b3ad250636023fb2c7827f - run: | - repo_dir="$GITHUB_WORKSPACE/cmap-fonts" - font_dir="$HOME/Library/Fonts" - mkdir -p $font_dir - find_command="find \"$repo_dir\" -name '*.[o,t]tf' -type f -print0" - eval $find_command | xargs -0 -I % - eval $find_command | xargs -0 -I % cp "%" "$font_dir/" - find "$font_dir" -name '*.[o,t]tf' -print0 | xargs -0 -I % - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v1 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install dependencies - run: | - message() - remotes::install_deps(dependencies = TRUE) - install.packages("pkgdown") - shell: Rscript {0} - - - name: Check Whitney availability in R - run: | - all_fonts <- systemfonts::system_fonts() - message("WHITNEY FONTS AUTOMATICALLY AVAILABLE TO SYSTEMFONTS:") - message(paste(all_fonts$name[grepl("^Whitney", all_fonts$name)], collapse = "\n")) - user_dir <- paste0(Sys.getenv("HOME"), "/Library/Fonts") - library_fonts <- list.files(user_dir) - message(paste0("WHITNEY FONTS IN ", user_dir, " (MUST BE REGISTERED):")) - message(paste(library_fonts[grepl("^Whitney", library_fonts)], collapse = "\n")) - shell: Rscript {0} - - - name: Install package - run: R CMD INSTALL . - - - name: Deploy package to live branch - if: ${{ github.ref == 'refs/heads/main' }} - run: | - echo "This is $GITHUB_REF. Deploying to gh-pages branch." - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(clean = TRUE)' - - - name: Deploy package to test branch - if: ${{ github.ref != 'refs/heads/main' }} - run: | - echo "This is $GITHUB_REF. Deploying to gh-pages-test branch." - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - Rscript -e 'pkgdown::deploy_to_branch(branch="gh-pages-test", clean = TRUE)' From 699f2da2118c39a4ad3d94f524471a1c27b91b73 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 3 May 2021 12:29:17 -0500 Subject: [PATCH 80/83] Modified text formatting example --- vignettes/finalize.Rmd | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index 8141939c..d777a3db 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -138,9 +138,11 @@ The title and caption blocks take HTML formatting tags, which you can use to man ```{r finalize5, message=FALSE} # A finalized line graph, with text tweaks finalize_plot(plot = p, - title = "Annual
unlinked passenger trips
(in millions)", - caption = "Source: Chicago Metropolitan Agency for Planning - analysis of Regional Transportation Authority data") + title = "Annual unlinked passenger trips
(in millions)", + caption = "Source:
    +
  • Chicago Metropolitan Agency for Planning analysis
  • +
  • Regional Transportation Authority data
  • +
") ``` ## Advanced customization @@ -153,8 +155,11 @@ finalize_plot(plot = p, # A debugged finalized plot finalize_plot(plot = p, title = "Annual unlinked passenger trips (in millions)", - caption = "Source: Chicago Metropolitan Agency for Planning - analysis of Regional Transportation Authority data", + caption = 'Source: Chicago + Metropolitan Agency for Planning analysis of + RTA1 data. +

+ 1 Regional Transportation Authority', debug = TRUE) ``` @@ -196,9 +201,8 @@ There is a fairly long list of possible margins that can be customized using the Here, the margins are visualized as they impact a finalized plot that has a sidebar: - + Here, the same margins are visualized as they impact a finalized plot with no sidebar: - - + From a1caf114ab1cfab48d970c0b6c37d4b22d46b210 Mon Sep 17 00:00:00 2001 From: Noel Peterson Date: Mon, 3 May 2021 12:30:21 -0500 Subject: [PATCH 81/83] Modified text formatting example --- vignettes/finalize.Rmd | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/vignettes/finalize.Rmd b/vignettes/finalize.Rmd index d777a3db..ff3063b5 100644 --- a/vignettes/finalize.Rmd +++ b/vignettes/finalize.Rmd @@ -139,10 +139,11 @@ The title and caption blocks take HTML formatting tags, which you can use to man # A finalized line graph, with text tweaks finalize_plot(plot = p, title = "Annual unlinked passenger trips
(in millions)", - caption = "Source:
    -
  • Chicago Metropolitan Agency for Planning analysis
  • -
  • Regional Transportation Authority data
  • -
") + caption = 'Source: Chicago + Metropolitan Agency for Planning analysis of + RTA1 data. +

+ 1 Regional Transportation Authority') ``` ## Advanced customization @@ -155,11 +156,8 @@ finalize_plot(plot = p, # A debugged finalized plot finalize_plot(plot = p, title = "Annual unlinked passenger trips (in millions)", - caption = 'Source: Chicago - Metropolitan Agency for Planning analysis of - RTA1 data. -

- 1 Regional Transportation Authority', + caption = "Source: Chicago Metropolitan Agency for Planning + analysis of Regional Transportation Authority data", debug = TRUE) ``` From 612c01e2ebeca08eab75e3f555a8b0362d526f85 Mon Sep 17 00:00:00 2001 From: Daniel Comeaux <58892984+dlcomeaux@users.noreply.github.com> Date: Mon, 3 May 2021 21:13:45 -0500 Subject: [PATCH 82/83] Handle edge case If there are multiple copies of a font installed (like is the case on my machine for whatever reason...not sure if I did that by mistake). --- R/utilities.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index fe75eee6..8c9421c6 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -112,8 +112,8 @@ gg_lwd_convert <- function(value, unit = "bigpts") { find_path <- function(filename, paths){ result <- grep(paste0("(\\\\|/)", filename, ".[ot]tf$"), paths, value = TRUE) - if(length(result) == 1){ - return(result) + if(length(result) >= 1){ + return(result[1]) } else { stop( paste0("Font '", filename, "' not found."), From 51d467e3accbe82271710e5c3e008600b7e0d664 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Tue, 4 May 2021 09:13:50 -0500 Subject: [PATCH 83/83] add path length requirement --- R/cmapplot.R | 87 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/R/cmapplot.R b/R/cmapplot.R index 2875a536..febdc0ea 100644 --- a/R/cmapplot.R +++ b/R/cmapplot.R @@ -51,48 +51,51 @@ whitney_paths <- grep("Whitney-", whitney_paths, value = TRUE) } - # Attempt to register preferred fonts using paths found above. The correct - # Whitney fonts may not be available (e.g. `whitney_paths` will have a length - # of 0 if no Whitney faces are located) - in this case, `find_path` will error - # and the try object will fail before `use_whitney` is set to TRUE. - try({ - - # register preferred strong font (Whitney Semibold), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$strong, - plain = find_path("Whitney-Semibold-Adv", whitney_paths), - bold = find_path("Whitney-Black-Adv", whitney_paths), - italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) - ) - - # register preferred regular font (Whitney Medium), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$regular, - plain = find_path("Whitney-Medium-Adv", whitney_paths), - bold = find_path("Whitney-Bold-Adv", whitney_paths), - italic = find_path("Whitney-MediumItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) - ) - - # register preferred light font (Whitney Book), with variants - systemfonts::register_font( - name = cmapplot_globals$preferred_font$light, - plain = find_path("Whitney-Book-Adv", whitney_paths), - bold = find_path("Whitney-Semibold-Adv", whitney_paths), - italic = find_path("Whitney-BookItal-Adv", whitney_paths), - bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) - ) - - packageStartupMessage(paste0( - "cmapplot has registered the following fonts for use in this R session:\n ", - paste(cmapplot_globals$preferred_font, collapse = ", ") - )) - - assign("use_whitney", - TRUE, - envir = cmapplot_globals) - }) + # Register preferred fonts using the paths found above. This will only be + # attempted if at least 10 paths are found, as 10 distinct faces are needed + # to register all possible variants of the three needed fonts. If the + # correct face cannot be found, `find_path` will error and the try object + # will fail before `use_whitney` is set to TRUE. + if (length(whitney_paths) >= 10){ + try({ + + # register preferred strong font (Whitney Semibold), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$strong, + plain = find_path("Whitney-Semibold-Adv", whitney_paths), + bold = find_path("Whitney-Black-Adv", whitney_paths), + italic = find_path("Whitney-SemiboldItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BlackItal-Adv", whitney_paths) + ) + + # register preferred regular font (Whitney Medium), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$regular, + plain = find_path("Whitney-Medium-Adv", whitney_paths), + bold = find_path("Whitney-Bold-Adv", whitney_paths), + italic = find_path("Whitney-MediumItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-BoldItal-Adv", whitney_paths) + ) + + # register preferred light font (Whitney Book), with variants + systemfonts::register_font( + name = cmapplot_globals$preferred_font$light, + plain = find_path("Whitney-Book-Adv", whitney_paths), + bold = find_path("Whitney-Semibold-Adv", whitney_paths), + italic = find_path("Whitney-BookItal-Adv", whitney_paths), + bolditalic = find_path("Whitney-SemiboldItal-Adv", whitney_paths) + ) + + packageStartupMessage(paste0( + "cmapplot has registered the following fonts for use in this R session:\n ", + paste(cmapplot_globals$preferred_font, collapse = ", ") + )) + + assign("use_whitney", + TRUE, + envir = cmapplot_globals) + }) + } } # If Whitney is available...