From ba9c5f8d58f5b4487c038d68e3f618824bb42977 Mon Sep 17 00:00:00 2001 From: Russ Hyde Date: Wed, 3 Apr 2024 10:26:38 +0100 Subject: [PATCH 1/4] refac(test): add function to make empty/non-empty dups tables --- tests/testthat/helper.R | 22 +++++++++++++++++++--- tests/testthat/test-dups-class.R | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index c288a42..5ca5af7 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -31,8 +31,10 @@ expect_equivalent_tbl <- function(object, expected, ..., info = NULL) { ) } -get_empty_dups_tbl <- function() { - tibble::tibble( +get_dups_tbl <- function( + ... +) { + empty_tbl <- tibble::tibble( file_a = character(0), file_b = character(0), block_a = integer(0), @@ -41,10 +43,24 @@ get_empty_dups_tbl <- function() { line_b = integer(0), score = numeric(0) ) + + user_tbl <- tibble::tibble(...) + + common_cols <- intersect(colnames(user_tbl), colnames(empty_tbl)) + + if (length(common_cols) == 0) { + return(dplyr::cross_join(user_tbl, empty_tbl)) + } + + dplyr::left_join( + user_tbl, + empty_tbl, + by = common_cols + ) } get_empty_dups_df <- function() { - as.data.frame(get_empty_dups_tbl(), stringsAsFactors = FALSE) + as.data.frame(get_dups_tbl(), stringsAsFactors = FALSE) } ############################################################################### diff --git a/tests/testthat/test-dups-class.R b/tests/testthat/test-dups-class.R index a4bf1ec..bbdb477 100644 --- a/tests/testthat/test-dups-class.R +++ b/tests/testthat/test-dups-class.R @@ -15,7 +15,7 @@ test_that("`dups` object can be converted to `data.frame`", { info = "dups -> dups conversion is an identity map" ) - y <- get_empty_dups_tbl() + y <- get_dups_tbl() dups <- as_dups(y) expect_equal( From 5e11595f1f348a5a718b674726e62e20b5be98ed Mon Sep 17 00:00:00 2001 From: Russ Hyde Date: Wed, 3 Apr 2024 10:56:41 +0100 Subject: [PATCH 2/4] test: print(dups, n = ...) works like printing a tibble --- tests/testthat/test-dups-class.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-dups-class.R b/tests/testthat/test-dups-class.R index bbdb477..4b728b4 100644 --- a/tests/testthat/test-dups-class.R +++ b/tests/testthat/test-dups-class.R @@ -28,3 +28,20 @@ test_that("`dups` object can be converted to `data.frame`", { test_that("non dups/data-frames can't be converted to dups", { expect_error(as_dups("NOT A data.frame or dups object")) }) + +describe("printing a 'dups' object", { + dups <- as_dups(get_dups_tbl(file_a = paste0(letters, ".R"))) + + it("includes the first line in the output", { + expect_output(print(dups), regexp = "a\\.R") + }) + + it("respects print(tibble, n = ...)", { + # "z.R" is on the last line of the table, it shouldn't be visible by default + # because `print(tibble)` shows the first 10 lines for large tables + expect_output(print(dups), regexp = "[^z].\\R") + # But when 26 lines of the table are printed, then the file "z.R" should be + # seen + expect_output(print(dups, n = 26), regexp = "z\\.R") + }) +}) From 3225c8fa59d488913a4f3258fc5a140162777fdb Mon Sep 17 00:00:00 2001 From: Russ Hyde Date: Wed, 3 Apr 2024 10:58:45 +0100 Subject: [PATCH 3/4] feat: print(dups, ...) passes additional arguments to print(tibble, ...) --- R/dups-class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dups-class.R b/R/dups-class.R index cb88c98..2a2303e 100644 --- a/R/dups-class.R +++ b/R/dups-class.R @@ -47,7 +47,7 @@ tibble::as_tibble # nocov start print.dups <- function(x, ...) { - print(as_tibble(x)) + print(as_tibble(x), ...) invisible(x) } # nocov end From 8240c60a9644aa0bb80dfeead69fd348020f5ef2 Mon Sep 17 00:00:00 2001 From: Russ Hyde Date: Wed, 3 Apr 2024 11:02:50 +0100 Subject: [PATCH 4/4] chore: bump news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 74faec2..d05a166 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # dupree (development version) +* Pass print(dups, ...) dots to print(tibble, ...) so that the number of output lines can be + specified in the output (thanks @mikemahoney218) * Update the CI workflows for pkgdown, test-coverage and R CMD check * use lintr >= 3, and update .lintr config file * Fixed linting across package