From dc23895293d88f1c95fb57da5e082585a0b58de1 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 22 Aug 2024 16:49:12 -0400 Subject: [PATCH 1/3] remove rematch2 and tibble deps --- DESCRIPTION | 5 +---- NEWS.md | 2 +- R/rematch.R | 26 ++++++++++++++++++++++++++ R/ses.R | 6 +++--- 4 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 R/rematch.R diff --git a/DESCRIPTION b/DESCRIPTION index 0fd41e6..1c04366 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,11 +19,8 @@ Imports: diffobj (>= 0.3.4), glue, methods, - rematch2, - rlang (>= 1.0.0), - tibble + rlang (>= 1.0.0) Suggests: - covr, R6, testthat (>= 3.0.0), withr, diff --git a/NEWS.md b/NEWS.md index f814799..27e70c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # waldo (development version) -* waldo no longer imports fansi (@olivroy, #192). +* waldo no longer imports fansi, tibble, and rematch2 (@olivroy, #192, #196). # waldo 0.5.2 diff --git a/R/rematch.R b/R/rematch.R new file mode 100644 index 0000000..24d2ad5 --- /dev/null +++ b/R/rematch.R @@ -0,0 +1,26 @@ +# Source copied from rematch2::re_match, but doesn't return tibble. +re_match <- function(text, pattern, perl = TRUE, ...) { + stopifnot(is.character(pattern), length(pattern) == 1, !is.na(pattern)) + text <- as.character(text) + match <- regexpr(pattern, text, perl = perl, ...) + start <- as.vector(match) + length <- attr(match, "match.length") + end <- start + length - 1L + matchstr <- substring(text, start, end) + matchstr[start == -1] <- NA_character_ + res <- data.frame( + stringsAsFactors = FALSE, .text = text, + .match = matchstr + ) + if (!is.null(attr(match, "capture.start"))) { + gstart <- attr(match, "capture.start") + glength <- attr(match, "capture.length") + gend <- gstart + glength - 1L + groupstr <- substring(text, gstart, gend) + groupstr[gstart == -1] <- NA_character_ + dim(groupstr) <- dim(gstart) + res <- cbind(groupstr, res, stringsAsFactors = FALSE) + } + names(res) <- c(attr(match, "capture.names"), ".text", ".match") + res +} diff --git a/R/ses.R b/R/ses.R index c35d062..1680116 100644 --- a/R/ses.R +++ b/R/ses.R @@ -16,7 +16,7 @@ ses <- function(x, y) { } out <- diffobj::ses(x, y, warn = FALSE, max.diffs = 100) - out <- rematch2::re_match(out, paste0( + out <- re_match(out, paste0( "(?:(?\\d+),)?(?\\d+)", "(?[acd])", "(?:(?\\d+),)?(?\\d+)" @@ -30,7 +30,7 @@ ses <- function(x, y) { out$y1 <- as.integer(out$y1) out$y2 <- as.integer(out$y2) - out + as.data.frame(out, stringsAsFactors = FALSE) } ses_elementwise <- function(x, y) { @@ -146,5 +146,5 @@ diff_complete <- function(diff) { } ses_df <- function(x1, x2, t, y1, y2) { - tibble::tibble(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2) + data.frame(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2, stringsAsFactors = FALSE) } From e5c94c0c0219b223e7ff011c221b8be43e5eb1cc Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 21 Oct 2024 08:57:56 -0500 Subject: [PATCH 2/3] Require R 4.0 and drop stringsAsFactors --- DESCRIPTION | 8 ++++---- NEWS.md | 1 + R/rematch.R | 7 ++----- R/ses.R | 4 ++-- tests/testthat/_snaps/compare-data-frame.md | 5 ++--- tests/testthat/_snaps/compare.md | 17 +---------------- tests/testthat/test-compare-data-frame.R | 4 ++-- 7 files changed, 14 insertions(+), 32 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d77b14c..5de5576 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,15 +12,15 @@ Description: Compare complex R objects and reveal the key differences. License: MIT + file LICENSE URL: https://waldo.r-lib.org, https://github.com/r-lib/waldo BugReports: https://github.com/r-lib/waldo/issues -Depends: - R (>= 3.6) -Imports: +Depends: + R (>= 4.0) +Imports: cli, diffobj (>= 0.3.4), glue, methods, rlang (>= 1.0.0) -Suggests: +Suggests: R6, testthat (>= 3.0.0), withr, diff --git a/NEWS.md b/NEWS.md index 8361979..2fe4c6e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # waldo (development version) * waldo no longer imports tibble and rematch2 (@olivroy, #196). +* waldo now requires R 4.0.0. # waldo 0.5.3 diff --git a/R/rematch.R b/R/rematch.R index 24d2ad5..307fadf 100644 --- a/R/rematch.R +++ b/R/rematch.R @@ -8,10 +8,7 @@ re_match <- function(text, pattern, perl = TRUE, ...) { end <- start + length - 1L matchstr <- substring(text, start, end) matchstr[start == -1] <- NA_character_ - res <- data.frame( - stringsAsFactors = FALSE, .text = text, - .match = matchstr - ) + res <- data.frame(.text = text, .match = matchstr) if (!is.null(attr(match, "capture.start"))) { gstart <- attr(match, "capture.start") glength <- attr(match, "capture.length") @@ -19,7 +16,7 @@ re_match <- function(text, pattern, perl = TRUE, ...) { groupstr <- substring(text, gstart, gend) groupstr[gstart == -1] <- NA_character_ dim(groupstr) <- dim(gstart) - res <- cbind(groupstr, res, stringsAsFactors = FALSE) + res <- cbind(groupstr, res) } names(res) <- c(attr(match, "capture.names"), ".text", ".match") res diff --git a/R/ses.R b/R/ses.R index 1680116..8e7ee20 100644 --- a/R/ses.R +++ b/R/ses.R @@ -30,7 +30,7 @@ ses <- function(x, y) { out$y1 <- as.integer(out$y1) out$y2 <- as.integer(out$y2) - as.data.frame(out, stringsAsFactors = FALSE) + as.data.frame(out) } ses_elementwise <- function(x, y) { @@ -146,5 +146,5 @@ diff_complete <- function(diff) { } ses_df <- function(x1, x2, t, y1, y2) { - data.frame(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2, stringsAsFactors = FALSE) + data.frame(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2) } diff --git a/tests/testthat/_snaps/compare-data-frame.md b/tests/testthat/_snaps/compare-data-frame.md index def3a71..7f608b0 100644 --- a/tests/testthat/_snaps/compare-data-frame.md +++ b/tests/testthat/_snaps/compare-data-frame.md @@ -43,9 +43,8 @@ # informative diff for changes Code - df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"), stringsAsFactors = FALSE) - df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"), - stringsAsFactors = FALSE) + df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c")) + df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c")) compare(df1, df2) Output old vs new diff --git a/tests/testthat/_snaps/compare.md b/tests/testthat/_snaps/compare.md index 427089c..8ec0294 100644 --- a/tests/testthat/_snaps/compare.md +++ b/tests/testthat/_snaps/compare.md @@ -383,21 +383,6 @@ Code compare(f1, f4, ignore_srcref = FALSE) Output - `attr(old, 'srcref')`: 2 8 2 33 8 33 2 2 - `attr(new, 'srcref')`: 14 8 16 1 8 1 14 16 - - `attr(body(old), 'srcref')` is length 1 - `attr(body(new), 'srcref')` is length 2 - - `attr(body(old), 'srcref')[[1]]`: 2 31 2 31 31 31 2 2 - `attr(body(new), 'srcref')[[1]]`: 14 31 14 31 31 31 14 14 - - `attr(body(old), 'srcref')[[2]]` is absent - `attr(body(new), 'srcref')[[2]]` is an S3 object of class , an integer vector - - `attr(body(old), 'wholeSrcref')`: 1 0 2 33 0 33 1 2 - `attr(body(new), 'wholeSrcref')`: 1 0 16 1 0 1 1 16 - `body(old)`: `{` `}` `body(new)`: `{` ` x + y` `}` Code @@ -421,7 +406,7 @@ compare(f2, f1, ignore_srcref = FALSE) Output `attr(old, 'srcref')` is a character vector ('{ }') - `attr(new, 'srcref')` is an S3 object of class , an integer vector + `attr(new, 'srcref')` is absent # can compare atomic vectors diff --git a/tests/testthat/test-compare-data-frame.R b/tests/testthat/test-compare-data-frame.R index a0f739d..6b18612 100644 --- a/tests/testthat/test-compare-data-frame.R +++ b/tests/testthat/test-compare-data-frame.R @@ -8,8 +8,8 @@ test_that("informative diff for additions and deletions", { test_that("informative diff for changes", { expect_snapshot({ - df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"), stringsAsFactors = FALSE) - df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"), stringsAsFactors = FALSE) + df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c")) + df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c")) compare(df1, df2) }) }) From f27386e0150496134c919c8798f325538c6e368e Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 21 Oct 2024 09:22:41 -0500 Subject: [PATCH 3/3] Remove unneeded data.frame --- R/ses.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ses.R b/R/ses.R index 8e7ee20..729ec9d 100644 --- a/R/ses.R +++ b/R/ses.R @@ -30,7 +30,7 @@ ses <- function(x, y) { out$y1 <- as.integer(out$y1) out$y2 <- as.integer(out$y2) - as.data.frame(out) + out } ses_elementwise <- function(x, y) {