From 72cd6233222a03352fa1fe177adf5d1cbe4fa06f Mon Sep 17 00:00:00 2001 From: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:59:06 +0100 Subject: [PATCH] Remove `stringr` dependency (#2530) Co-authored-by: Yihui Xie --- CITATION.cff | 14 +------------- DESCRIPTION | 1 - NEWS.md | 2 ++ R/base64.R | 4 +++- tests/testthat/site/PageA.Rmd | 2 +- tests/testthat/test-site.R | 12 ++++++------ 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index d5a4e19d00..17d2107acf 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ # CITATION file created with {cffr} R package, v0.4.1 # See also: https://docs.ropensci.org/cffr/ # ----------------------------------------------------------- - + cff-version: 1.2.0 message: 'To cite package "rmarkdown" in publications use:' type: software @@ -271,18 +271,6 @@ references: year: '2023' institution: name: R Foundation for Statistical Computing -- type: software - title: stringr - abstract: 'stringr: Simple, Consistent Wrappers for Common String Operations' - notes: Imports - url: https://stringr.tidyverse.org - repository: https://CRAN.R-project.org/package=stringr - authors: - - family-names: Wickham - given-names: Hadley - email: hadley@rstudio.com - year: '2023' - version: '>= 1.2.0' - type: software title: tinytex abstract: 'tinytex: Helper Functions to Install and Maintain TeX Live, and Compile diff --git a/DESCRIPTION b/DESCRIPTION index 1fedf3c348..f6df81383f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -65,7 +65,6 @@ Imports: jsonlite, knitr (>= 1.22), methods, - stringr (>= 1.2.0), tinytex (>= 0.31), tools, utils, diff --git a/NEWS.md b/NEWS.md index 6c0082db81..467e802313 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ rmarkdown 2.26 - Get rid of the superfluous warning in `find_pandoc()` (thanks, @jszhao, #2527). +- Removed the **stringr** dependency since it is used only once in the package and the equivalent base R code is simple enough (thanks, @etiennebacher, #2530). + rmarkdown 2.25 ================================================================================ diff --git a/R/base64.R b/R/base64.R index 65a1aa28a2..2a0ed0b625 100644 --- a/R/base64.R +++ b/R/base64.R @@ -10,7 +10,9 @@ process_html_res <- function(html, reg, processor) { character(1) ) } - html <- stringr::str_replace_all(html, reg, process_img_src) + m <- gregexpr(reg, html, perl = TRUE) + regmatches(html, m) <- lapply(regmatches(html, m), process_img_src) + strsplit(html, "\n", fixed = TRUE)[[1]] } diff --git a/tests/testthat/site/PageA.Rmd b/tests/testthat/site/PageA.Rmd index 7b049beea8..4b6d0717c1 100644 --- a/tests/testthat/site/PageA.Rmd +++ b/tests/testthat/site/PageA.Rmd @@ -12,7 +12,7 @@ knitr::opts_chunk$set(echo = TRUE) Let's load a package (from existing dependencies) and make sure it's not on the search path when rendering a subsequent file. ```{r} -library(stringr) +library(tinytex) plot(cars) ``` diff --git a/tests/testthat/test-site.R b/tests/testthat/test-site.R index 4c1d469061..924efa23bc 100644 --- a/tests/testthat/test-site.R +++ b/tests/testthat/test-site.R @@ -66,9 +66,9 @@ test_that("render_site respects 'new_session' in the config", { a <- readLines(file.path(site_dir, "_site", "PageA.html")) b <- readLines(file.path(site_dir, "_site", "PageB.html")) - # pkg loaded in PageA (stringr) should show up in search path of PageB - expect_match(a, "library(stringr)", fixed = TRUE, all = FALSE) - expect_true(any(grepl("stringr", b, fixed = TRUE))) + # pkg loaded in PageA (tinytex) should show up in search path of PageB + expect_match(a, "library(tinytex)", fixed = TRUE, all = FALSE) + expect_true(any(grepl("tinytex", b, fixed = TRUE))) # edit config --> new_session: true cat("new_session: true", file = file.path(site_dir, "_site.yml"), append = TRUE) @@ -77,9 +77,9 @@ test_that("render_site respects 'new_session' in the config", { a <- readLines(file.path(site_dir, "_site", "PageA.html")) b <- readLines(file.path(site_dir, "_site", "PageB.html")) - # pkg loaded in PageA (stringr) should NOT show up in search path of PageB - expect_match(a, "library(stringr)", fixed = TRUE, all = FALSE) - expect_false(any(grepl("stringr", b, fixed = TRUE))) + # pkg loaded in PageA (tinytex) should NOT show up in search path of PageB + expect_match(a, "library(tinytex)", fixed = TRUE, all = FALSE) + expect_false(any(grepl("tinytex", b, fixed = TRUE))) }) test_that("clean_site gives notices before removing", {