diff --git a/NAMESPACE b/NAMESPACE index 9234e31..9c201c6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,7 +2,6 @@ S3method(print,datadiff_coverage) S3method(print,datadiff_report) -export("%||%") export(add_tolerance_columns) export(analyze_columns) export(compare_datasets_from_yaml) diff --git a/NEWS.md b/NEWS.md index 5cc91b5..cbb9a2c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -88,6 +88,18 @@ ## Bug fixes +* Three NEWS-vs-code contradictions introduced by the "Perf (#1)" commit after + the 0.4.4 release are resolved in the direction 0.4.4 had announced or the + docs now tell the truth: `%||%` is internal again (exporting it masked + rlang's and base R's own operator at load time; the test that locked the + accidental re-export now locks the opposite), the default rules-template + label prefix is "comparison" (was still the French "comparaison"), and the + vignette states the real report language default (`lang = "fr"`, it claimed + English). The three exported helpers that no user-facing doc mentioned + (`normalize_text()`, `validate_row_counts()`, `setup_pointblank_agent()`) + are now documented in the vignette's utility-functions section with real + use cases (issue #26). + * `setup_pointblank_agent()` cleanup: the `cols_reference` argument was never read (verified by grep since its introduction) and is now deprecated (warning when supplied, removal planned); the local equality steps validate diff --git a/R/compare_datasets_from_yaml.R b/R/compare_datasets_from_yaml.R index 0970389..6f2d58d 100644 --- a/R/compare_datasets_from_yaml.R +++ b/R/compare_datasets_from_yaml.R @@ -70,8 +70,8 @@ write_rules_template <- function(data_reference, } } validate_label(label) - if (is.null(label) || label == "") {label <- paste("comparaison", deparse1(substitute(data_reference))) - + if (is.null(label) || label == "") { + label <- paste("comparison", deparse1(substitute(data_reference))) } types <- detect_column_types(.ref_schema) # With equal_mode "normalized", writing the default FALSE flags would diff --git a/R/utils.R b/R/utils.R index a8dba33..f38d9af 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,12 +1,12 @@ -#' Operator for default values -#' -#' Returns y if x is NULL, otherwise returns x -#' @name or_operator -#' @param x Value to check -#' @param y Default value to return if x is NULL -#' @return x if not NULL, otherwise y -#' @export -`%||%` <- function(x, y) if (is.null(x)) y else x +# Default-value operator: y if x is NULL, otherwise x. Internal: exporting it +# would mask rlang's and base R's (R >= 4.4) own %||% at load time. +`%||%` <- function(x, y) { + if (is.null(x)) { + y + } else { + x + } +} get_col_names <- function(x) { nms <- colnames(x) diff --git a/man/or_operator.Rd b/man/or_operator.Rd deleted file mode 100644 index 20863e8..0000000 --- a/man/or_operator.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{or_operator} -\alias{or_operator} -\alias{\%||\%} -\title{Operator for default values} -\usage{ -x \%||\% y -} -\arguments{ -\item{x}{Value to check} - -\item{y}{Default value to return if x is NULL} -} -\value{ -x if not NULL, otherwise y -} -\description{ -Returns y if x is NULL, otherwise returns x -} diff --git a/tests/testthat/test-input-validation.R b/tests/testthat/test-input-validation.R index 2811fc0..3f1d49f 100644 --- a/tests/testthat/test-input-validation.R +++ b/tests/testthat/test-input-validation.R @@ -138,18 +138,18 @@ test_that("write_rules_template handles label edge cases", { df <- data.frame(id = 1:2, value = 1:2) # Test NULL label (should use default) - template_path <- "test_null_label.yaml" + template_path <- tempfile(fileext = ".yaml") + on.exit(unlink(template_path), add = TRUE) write_rules_template(df, key = "id", label = NULL, path = template_path) rules <- read_rules(template_path) - expect_match(rules$defaults$label, "comparaison") - unlink(template_path) + expect_match(rules$defaults$label, "comparison") # Test empty label (should use default) - template_path <- "test_empty_label.yaml" - write_rules_template(df, key = "id", label = "", path = template_path) - rules <- read_rules(template_path) - expect_match(rules$defaults$label, "comparaison") - unlink(template_path) + template_path2 <- tempfile(fileext = ".yaml") + on.exit(unlink(template_path2), add = TRUE) + write_rules_template(df, key = "id", label = "", path = template_path2) + rules <- read_rules(template_path2) + expect_match(rules$defaults$label, "comparison") # Test very long label long_label <- paste(rep("very_long_label", 100), collapse = "_") diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 128dec1..e52e62f 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -5,8 +5,9 @@ test_that("%||% operator works correctly", { expect_equal(object = NULL %||% NULL, expected = NULL) }) -test_that("%||% is exported from the package namespace", { - expect_true("%||%" %in% getNamespaceExports("datadiff")) +test_that("%||% is internal (not exported), per NEWS 0.4.4", { + # Exporting it masks rlang's and base R's (R >= 4.4) own %||% at load time + expect_false("%||%" %in% getNamespaceExports("datadiff")) }) test_that("normalize_text handles basic cases", { diff --git a/vignettes/datadiff.Rmd b/vignettes/datadiff.Rmd index 530fbf5..6003f36 100644 --- a/vignettes/datadiff.Rmd +++ b/vignettes/datadiff.Rmd @@ -801,11 +801,42 @@ cmp_annotated <- add_tolerance_columns(cmp, "value", rules_debug, cmp_annotated[, c("value__absdiff", "value__thresh", "value__ok")] ``` +### `normalize_text()` + +The text-normalization primitive used by `preprocess_dataframe()`, handy on +its own to normalize a vector the same way a comparison would: + +```{r normalize-text} +normalize_text(c(" Hello ", "WORLD"), case_insensitive = TRUE, trim = TRUE) +``` + +### `validate_row_counts()` + +Computes the row-count validation information (counts, expected count, +tolerance) for a pair of datasets and a rules object, without running the +full comparison: + +```{r validate-row-counts} +rules_rc <- list(row_validation = list(check_count = TRUE, + expected_count = NULL, tolerance = 0)) +validate_row_counts(ref, cand, rules = rules_rc) +``` + +### `setup_pointblank_agent()` + +Builds the configured (not yet interrogated) pointblank agent the comparison +uses, for advanced consumers who want to add their own steps before +interrogating. The equality steps validate `