From d23fcba99883e52f095b7b389bc76ef3326f9f25 Mon Sep 17 00:00:00 2001 From: gowerc Date: Tue, 26 Aug 2025 21:23:06 +0100 Subject: [PATCH 1/4] better support for deparse --- R/diffdf.R | 11 ++- tests/testthat/_snaps/miscellaneous.md | 123 +++++++++++++++++++++++++ tests/testthat/test-miscellaneous.R | 28 ++++++ 3 files changed, 160 insertions(+), 2 deletions(-) diff --git a/R/diffdf.R b/R/diffdf.R index 6f955380..d0d6bb3a 100644 --- a/R/diffdf.R +++ b/R/diffdf.R @@ -113,8 +113,15 @@ diffdf <- function( class(COMPARE) <- c("diffdf", "list") - BASE_NAME <- deparse(substitute(base)) - COMP_NAME <- deparse(substitute(compare)) + BASE_NAME <- deparse(substitute(base), width.cutoff = 30L) + COMP_NAME <- deparse(substitute(compare), width.cutoff = 30L) + if (length(BASE_NAME) > 1) { + BASE_NAME <- "" + } + if (length(COMP_NAME) > 1) { + COMP_NAME <- "" + } + COMPARE[["DataSummary"]] <- construct_issue( value = describe_dataframe(BASE, COMP, BASE_NAME, COMP_NAME), message = "Summary of BASE and COMPARE" diff --git a/tests/testthat/_snaps/miscellaneous.md b/tests/testthat/_snaps/miscellaneous.md index d443a7c5..f1a53bed 100644 --- a/tests/testthat/_snaps/miscellaneous.md +++ b/tests/testthat/_snaps/miscellaneous.md @@ -305,3 +305,126 @@ +# #133 - Nested calls don't throw error with deparse + + Code + diffdf(d1, d2) + Condition + Warning in `diffdf()`: + + Not all Values Compared Equal + Output + Differences found between the objects! + + Summary of BASE and COMPARE + ================================================================== + PROPERTY BASE COMP + ------------------------------------------------------------------ + Name d1 d2 + Class "tbl_df, tbl, data.frame" "tbl_df, tbl, data.frame" + Rows(#) 4 4 + Columns(#) 2 2 + ------------------------------------------------------------------ + + + Not all Values Compared Equal + ============================= + Variable No of Differences + ----------------------------- + x 4 + ----------------------------- + + + ======================================== + VARIABLE ..ROWNUMBER.. BASE COMPARE + ---------------------------------------- + x 1 1 2 + x 2 2 3 + x 3 3 4 + x 4 4 5 + ---------------------------------------- + + + +--- + + Code + diffdf(d1, dplyr::mutate(d1, x = x + 1)) + Condition + Warning in `diffdf()`: + + Not all Values Compared Equal + Output + Differences found between the objects! + + Summary of BASE and COMPARE + ======================================================================= + PROPERTY BASE COMP + ----------------------------------------------------------------------- + Name d1 "dplyr::mutate(d1, x = x + 1)" + Class "tbl_df, tbl, data.frame" "tbl_df, tbl, data.frame" + Rows(#) 4 4 + Columns(#) 2 2 + ----------------------------------------------------------------------- + + + Not all Values Compared Equal + ============================= + Variable No of Differences + ----------------------------- + x 4 + ----------------------------- + + + ======================================== + VARIABLE ..ROWNUMBER.. BASE COMPARE + ---------------------------------------- + x 1 1 2 + x 2 2 3 + x 3 3 4 + x 4 4 5 + ---------------------------------------- + + + +--- + + Code + diffdf(d1, dplyr::mutate(d1, x = x + x + x + x)) + Condition + Warning in `diffdf()`: + + Not all Values Compared Equal + Output + Differences found between the objects! + + Summary of BASE and COMPARE + ================================================================== + PROPERTY BASE COMP + ------------------------------------------------------------------ + Name d1 + Class "tbl_df, tbl, data.frame" "tbl_df, tbl, data.frame" + Rows(#) 4 4 + Columns(#) 2 2 + ------------------------------------------------------------------ + + + Not all Values Compared Equal + ============================= + Variable No of Differences + ----------------------------- + x 4 + ----------------------------- + + + ======================================== + VARIABLE ..ROWNUMBER.. BASE COMPARE + ---------------------------------------- + x 1 1 4 + x 2 2 8 + x 3 3 12 + x 4 4 16 + ---------------------------------------- + + + diff --git a/tests/testthat/test-miscellaneous.R b/tests/testthat/test-miscellaneous.R index 9ae054eb..e8a83d9f 100644 --- a/tests/testthat/test-miscellaneous.R +++ b/tests/testthat/test-miscellaneous.R @@ -252,3 +252,31 @@ test_that("datetimes compare as expected", { print(res) ) }) + + +test_that("#133 - Nested calls don't throw error with deparse", { + d1 <- tibble(id = c(1, 2, 3, 4), x = c(1, 2, 3, 4)) + + expect_no_condition({ + tibble(id = c(1, 2, 3, 4), x = c(1, 2, 3, 4)) |> + dplyr::mutate(x = x + 1) |> + diffdf(d1, suppress_warnings = TRUE) + }) + + d2 <- tibble(id = c(1, 2, 3, 4), x = c(1, 2, 3, 4) + 1) + expect_snapshot(diffdf(d1, d2)) + + expect_snapshot( + diffdf( + d1, + d1 |> dplyr::mutate(x = x + 1) + ) + ) + + expect_snapshot( + diffdf( + d1, + d1 |> dplyr::mutate(x = x + x + x + x) + ) + ) +}) From d7f06de6be2408c95a937db2196902801f2244e0 Mon Sep 17 00:00:00 2001 From: gowerc Date: Tue, 26 Aug 2025 21:33:53 +0100 Subject: [PATCH 2/4] lintr --- R/diffdf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/diffdf.R b/R/diffdf.R index d0d6bb3a..1964d6d0 100644 --- a/R/diffdf.R +++ b/R/diffdf.R @@ -422,7 +422,7 @@ diffdf <- function( #' @export diffdf_has_issues <- function(x) { if (class(x)[[1]] != "diffdf") stop("x is not an diffdf object") - return(length(x) != 0) + length(x) != 0 } From 9e8c6340c2672a6302fb031dfb56351f5a50a09b Mon Sep 17 00:00:00 2001 From: gowerc Date: Tue, 14 Oct 2025 20:59:34 +0100 Subject: [PATCH 3/4] updated headers --- R/diffdf.R | 6 +-- tests/testthat/_snaps/miscellaneous.md | 57 ++++++++++++++++++-------- tests/testthat/test-miscellaneous.R | 16 ++++++-- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/R/diffdf.R b/R/diffdf.R index 1847ee19..1039512a 100644 --- a/R/diffdf.R +++ b/R/diffdf.R @@ -114,12 +114,12 @@ diffdf <- function( BASE_NAME <- deparse(substitute(base), width.cutoff = 30L) - COMP_NAME <- deparse(substitute(compare), width.cutoff = 30L) if (length(BASE_NAME) > 1) { - BASE_NAME <- "" + BASE_NAME <- "" } + COMP_NAME <- deparse(substitute(compare), width.cutoff = 30L) if (length(COMP_NAME) > 1) { - COMP_NAME <- "" + COMP_NAME <- "" } COMPARE[["DataSummary"]] <- construct_issue( diff --git a/tests/testthat/_snaps/miscellaneous.md b/tests/testthat/_snaps/miscellaneous.md index d01e8c15..798a7be8 100644 --- a/tests/testthat/_snaps/miscellaneous.md +++ b/tests/testthat/_snaps/miscellaneous.md @@ -308,11 +308,7 @@ # #133 - Nested calls don't throw error with deparse Code - diffdf(d1, d2) - Condition - Warning in `diffdf()`: - - Not all Values Compared Equal + diffdf(d1, d2, suppress_warnings = TRUE) Output Differences found between the objects! @@ -349,11 +345,7 @@ --- Code - diffdf(d1, dplyr::mutate(d1, x = x + 1)) - Condition - Warning in `diffdf()`: - - Not all Values Compared Equal + diffdf(d1, dplyr::mutate(d1, x = x + 1), suppress_warnings = TRUE) Output Differences found between the objects! @@ -390,11 +382,7 @@ --- Code - diffdf(d1, dplyr::mutate(d1, x = x + x + x + x)) - Condition - Warning in `diffdf()`: - - Not all Values Compared Equal + diffdf(d1, dplyr::mutate(d1, x = x + x + x + x), suppress_warnings = TRUE) Output Differences found between the objects! @@ -402,7 +390,7 @@ ================================================================== PROPERTY BASE COMP ------------------------------------------------------------------ - Name d1 + Name d1 Class "tbl_df, tbl, data.frame" "tbl_df, tbl, data.frame" Rows(#) 4 4 Columns(#) 2 2 @@ -428,6 +416,43 @@ +--- + + Code + diffdf(dplyr::mutate(d1, x = x + x + x + x), d1, suppress_warnings = TRUE) + Output + Differences found between the objects! + + Summary of BASE and COMPARE + ================================================================== + PROPERTY BASE COMP + ------------------------------------------------------------------ + Name d1 + Class "tbl_df, tbl, data.frame" "tbl_df, tbl, data.frame" + Rows(#) 4 4 + Columns(#) 2 2 + ------------------------------------------------------------------ + + + Not all Values Compared Equal + ============================= + Variable No of Differences + ----------------------------- + x 4 + ----------------------------- + + + ======================================== + VARIABLE ..ROWNUMBER.. BASE COMPARE + ---------------------------------------- + x 1 4 1 + x 2 8 2 + x 3 12 3 + x 4 16 4 + ---------------------------------------- + + + # `as_ascii_table() can handle missing datetimes (#132) Code diff --git a/tests/testthat/test-miscellaneous.R b/tests/testthat/test-miscellaneous.R index e9ae546d..78b12e74 100644 --- a/tests/testthat/test-miscellaneous.R +++ b/tests/testthat/test-miscellaneous.R @@ -264,19 +264,29 @@ test_that("#133 - Nested calls don't throw error with deparse", { }) d2 <- tibble(id = c(1, 2, 3, 4), x = c(1, 2, 3, 4) + 1) - expect_snapshot(diffdf(d1, d2)) + expect_snapshot(diffdf(d1, d2, suppress_warnings = TRUE)) + + expect_snapshot( + diffdf( + d1, + d1 |> dplyr::mutate(x = x + 1), + suppress_warnings = TRUE + ) + ) expect_snapshot( diffdf( d1, - d1 |> dplyr::mutate(x = x + 1) + d1 |> dplyr::mutate(x = x + x + x + x), + suppress_warnings = TRUE ) ) expect_snapshot( diffdf( + d1 |> dplyr::mutate(x = x + x + x + x), d1, - d1 |> dplyr::mutate(x = x + x + x + x) + suppress_warnings = TRUE ) ) }) From c2470afce9225183fad28885de130f1062ac38bc Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 14 Oct 2025 20:01:45 +0000 Subject: [PATCH 4/4] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5ef666c3..21744c05 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,7 +31,7 @@ Suggests: covr, bit64, withr -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 Roxygen: list(markdown = TRUE) VignetteBuilder: knitr License: MIT + file LICENSE