Skip to content

Commit 603db7a

Browse files
olivroyhadley
andauthored
remove rematch2 and tibble deps (#196)
* remove rematch2 and tibble deps * Require R 4.0 and drop stringsAsFactors Co-authored-by: Hadley Wickham <[email protected]>
1 parent 02026e1 commit 603db7a

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

DESCRIPTION

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@ Description: Compare complex R objects and reveal the key differences.
1212
License: MIT + file LICENSE
1313
URL: https://waldo.r-lib.org, https://github.com/r-lib/waldo
1414
BugReports: https://github.com/r-lib/waldo/issues
15-
Depends:
16-
R (>= 3.6)
17-
Imports:
15+
Depends:
16+
R (>= 4.0)
17+
Imports:
1818
cli,
1919
diffobj (>= 0.3.4),
2020
glue,
2121
methods,
22-
rematch2,
23-
rlang (>= 1.0.0),
24-
tibble
25-
Suggests:
26-
covr,
22+
rlang (>= 1.0.0)
23+
Suggests:
2724
R6,
2825
testthat (>= 3.0.0),
2926
withr,

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# waldo (development version)
22

3+
* waldo no longer imports tibble and rematch2 (@olivroy, #196).
4+
* waldo now requires R 4.0.0.
5+
36
# waldo 0.5.3
47

58
* waldo no longer imports fansi (@olivroy, #192).

R/rematch.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Source copied from rematch2::re_match, but doesn't return tibble.
2+
re_match <- function(text, pattern, perl = TRUE, ...) {
3+
stopifnot(is.character(pattern), length(pattern) == 1, !is.na(pattern))
4+
text <- as.character(text)
5+
match <- regexpr(pattern, text, perl = perl, ...)
6+
start <- as.vector(match)
7+
length <- attr(match, "match.length")
8+
end <- start + length - 1L
9+
matchstr <- substring(text, start, end)
10+
matchstr[start == -1] <- NA_character_
11+
res <- data.frame(.text = text, .match = matchstr)
12+
if (!is.null(attr(match, "capture.start"))) {
13+
gstart <- attr(match, "capture.start")
14+
glength <- attr(match, "capture.length")
15+
gend <- gstart + glength - 1L
16+
groupstr <- substring(text, gstart, gend)
17+
groupstr[gstart == -1] <- NA_character_
18+
dim(groupstr) <- dim(gstart)
19+
res <- cbind(groupstr, res)
20+
}
21+
names(res) <- c(attr(match, "capture.names"), ".text", ".match")
22+
res
23+
}

R/ses.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ses <- function(x, y) {
1616
}
1717

1818
out <- diffobj::ses(x, y, warn = FALSE, max.diffs = 100)
19-
out <- rematch2::re_match(out, paste0(
19+
out <- re_match(out, paste0(
2020
"(?:(?<x1>\\d+),)?(?<x2>\\d+)",
2121
"(?<t>[acd])",
2222
"(?:(?<y1>\\d+),)?(?<y2>\\d+)"
@@ -146,5 +146,5 @@ diff_complete <- function(diff) {
146146
}
147147

148148
ses_df <- function(x1, x2, t, y1, y2) {
149-
tibble::tibble(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2)
149+
data.frame(x1 = x1, x2 = x2, t = t, y1 = y1, y2 = y2)
150150
}

tests/testthat/_snaps/compare-data-frame.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
# informative diff for changes
4444

4545
Code
46-
df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"), stringsAsFactors = FALSE)
47-
df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"),
48-
stringsAsFactors = FALSE)
46+
df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"))
47+
df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"))
4948
compare(df1, df2)
5049
Output
5150
old vs new

tests/testthat/test-compare-data-frame.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ test_that("informative diff for additions and deletions", {
88

99
test_that("informative diff for changes", {
1010
expect_snapshot({
11-
df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"), stringsAsFactors = FALSE)
12-
df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"), stringsAsFactors = FALSE)
11+
df1 <- data.frame(x = 1:3, y = 1, z = c("a", "b", "c"))
12+
df2 <- data.frame(x = c(1, 100, 3), y = 1, z = c("a", "B", "c"))
1313
compare(df1, df2)
1414
})
1515
})

0 commit comments

Comments
 (0)