Skip to content

Commit 690605c

Browse files
authored
Merge pull request #91 from russHyde/pass-dots
Pass dots
2 parents 1191773 + 8240c60 commit 690605c

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# dupree (development version)
22

3+
* Pass print(dups, ...) dots to print(tibble, ...) so that the number of output lines can be
4+
specified in the output (thanks @mikemahoney218)
35
* Update the CI workflows for pkgdown, test-coverage and R CMD check
46
* use lintr >= 3, and update .lintr config file
57
* Fixed linting across package

R/dups-class.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ tibble::as_tibble
4747

4848
# nocov start
4949
print.dups <- function(x, ...) {
50-
print(as_tibble(x))
50+
print(as_tibble(x), ...)
5151
invisible(x)
5252
}
5353
# nocov end

tests/testthat/helper.R

+19-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ expect_equivalent_tbl <- function(object, expected, ..., info = NULL) {
3131
)
3232
}
3333

34-
get_empty_dups_tbl <- function() {
35-
tibble::tibble(
34+
get_dups_tbl <- function(
35+
...
36+
) {
37+
empty_tbl <- tibble::tibble(
3638
file_a = character(0),
3739
file_b = character(0),
3840
block_a = integer(0),
@@ -41,10 +43,24 @@ get_empty_dups_tbl <- function() {
4143
line_b = integer(0),
4244
score = numeric(0)
4345
)
46+
47+
user_tbl <- tibble::tibble(...)
48+
49+
common_cols <- intersect(colnames(user_tbl), colnames(empty_tbl))
50+
51+
if (length(common_cols) == 0) {
52+
return(dplyr::cross_join(user_tbl, empty_tbl))
53+
}
54+
55+
dplyr::left_join(
56+
user_tbl,
57+
empty_tbl,
58+
by = common_cols
59+
)
4460
}
4561

4662
get_empty_dups_df <- function() {
47-
as.data.frame(get_empty_dups_tbl(), stringsAsFactors = FALSE)
63+
as.data.frame(get_dups_tbl(), stringsAsFactors = FALSE)
4864
}
4965

5066
###############################################################################

tests/testthat/test-dups-class.R

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_that("`dups` object can be converted to `data.frame`", {
1515
info = "dups -> dups conversion is an identity map"
1616
)
1717

18-
y <- get_empty_dups_tbl()
18+
y <- get_dups_tbl()
1919
dups <- as_dups(y)
2020

2121
expect_equal(
@@ -28,3 +28,20 @@ test_that("`dups` object can be converted to `data.frame`", {
2828
test_that("non dups/data-frames can't be converted to dups", {
2929
expect_error(as_dups("NOT A data.frame or dups object"))
3030
})
31+
32+
describe("printing a 'dups' object", {
33+
dups <- as_dups(get_dups_tbl(file_a = paste0(letters, ".R")))
34+
35+
it("includes the first line in the output", {
36+
expect_output(print(dups), regexp = "a\\.R")
37+
})
38+
39+
it("respects print(tibble, n = ...)", {
40+
# "z.R" is on the last line of the table, it shouldn't be visible by default
41+
# because `print(tibble)` shows the first 10 lines for large tables
42+
expect_output(print(dups), regexp = "[^z].\\R")
43+
# But when 26 lines of the table are printed, then the file "z.R" should be
44+
# seen
45+
expect_output(print(dups, n = 26), regexp = "z\\.R")
46+
})
47+
})

0 commit comments

Comments
 (0)