Skip to content

Commit

Permalink
remove rematch2 and tibble deps (#196)
Browse files Browse the repository at this point in the history
* remove rematch2 and tibble deps
* Require R 4.0 and drop stringsAsFactors

Co-authored-by: Hadley Wickham <[email protected]>
  • Loading branch information
olivroy and hadley authored Oct 21, 2024
1 parent 02026e1 commit 603db7a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
13 changes: 5 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +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,
rematch2,
rlang (>= 1.0.0),
tibble
Suggests:
covr,
rlang (>= 1.0.0)
Suggests:
R6,
testthat (>= 3.0.0),
withr,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# waldo (development version)

* waldo no longer imports tibble and rematch2 (@olivroy, #196).
* waldo now requires R 4.0.0.

# waldo 0.5.3

* waldo no longer imports fansi (@olivroy, #192).
Expand Down
23 changes: 23 additions & 0 deletions R/rematch.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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(.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)
}
names(res) <- c(attr(match, "capture.names"), ".text", ".match")
res
}
4 changes: 2 additions & 2 deletions R/ses.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"(?:(?<x1>\\d+),)?(?<x2>\\d+)",
"(?<t>[acd])",
"(?:(?<y1>\\d+),)?(?<y2>\\d+)"
Expand Down Expand Up @@ -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)
}
5 changes: 2 additions & 3 deletions tests/testthat/_snaps/compare-data-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-compare-data-frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down

0 comments on commit 603db7a

Please sign in to comment.