From 6d2789e4a5b01d58097e9d85789be5fe43d126df Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Mon, 2 Dec 2024 02:59:09 -0500 Subject: [PATCH] fix: Monkey patch for gridtext@v0.1.5 Needed to preserve the ` ` in SVG output. Connects with . --- analysis/ctgov.R | 1 + analysis/ctgov/plot_stacked_chart.R | 18 ++++++++++++++++++ flake.nix | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/analysis/ctgov.R b/analysis/ctgov.R index bff3067..70994db 100644 --- a/analysis/ctgov.R +++ b/analysis/ctgov.R @@ -19,6 +19,7 @@ pacman::p_load( broom, tidyr, assertthat, + testthat, fs, glue, listr, diff --git a/analysis/ctgov/plot_stacked_chart.R b/analysis/ctgov/plot_stacked_chart.R index 2674431..2a40f5a 100644 --- a/analysis/ctgov/plot_stacked_chart.R +++ b/analysis/ctgov/plot_stacked_chart.R @@ -1,5 +1,20 @@ #### Plot stacked chart of intervals {{{ +### +### + +# Local override of str_squish to preserve   +local_str_squish <- function(string) { + stringi::stri_trim_both(stringr::str_replace_all(string, '[[\\s]-[\u00A0]]+', " ")) +} + +orig.str_split <- stringr::str_split +local_str_split <- function (string, pattern, n = Inf, simplify = FALSE) { + if( pattern == "[[:space:]]+" ) { + pattern <- "[[:space:]-[\u00A0]]+" + } + orig.str_split(string, pattern, n, simplify) +} categorize_intervals <- function(interval_length, breakpoints) { label_incomplete <- as.character( @@ -99,6 +114,9 @@ plot.windows.stacked.chart <- list_rbind() fig.result_reported_within.stacked_area <- { + # Cleaner than `assignInNamespace` + local_mocked_bindings(str_squish = local_str_squish, .package = 'stringr') + local_mocked_bindings(str_split = local_str_split, .package = 'stringr') df <- windows.result_reported_within |> mutate( diff --git a/flake.nix b/flake.nix index 40520b8..15c22db 100644 --- a/flake.nix +++ b/flake.nix @@ -81,7 +81,7 @@ pacman parsedate patchwork purrr readr rlang RPostgres scales stringr survival survminer svglite - this_path tidyr tidyverse + testthat this_path tidyr tidyverse vroom yaml ];