Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/compare_datasets_from_yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
20 changes: 0 additions & 20 deletions man/or_operator.Rd

This file was deleted.

16 changes: 8 additions & 8 deletions tests/testthat/test-input-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "_")
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Comment on lines +8 to +10

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faux positif de la meme classe que ceux refutes sur les PRs #43/#44 : tests/testthat.R utilise test_check("datadiff"), dont l'environnement de test est un clone de asNamespace("datadiff") - dans cet environnement, %||% resout vers l'implementation INTERNE de datadiff, pas vers rlang/base (verifie empiriquement sous le harnais installe, test_dir(load_package = "installed")). Le test exerce bien notre operateur.

})

test_that("normalize_text handles basic cases", {
Expand Down
33 changes: 32 additions & 1 deletion vignettes/datadiff.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<col>__eq` booleans and the
tolerance steps expect precomputed `<col>__ok` booleans (see
`add_tolerance_columns()`); most users never need to call it directly.

---

## 14. Language and locale

By default, pointblank reports are rendered in English. You can change
By default, pointblank reports are rendered in French (`lang = "fr"`,
`locale = "fr_FR"`; override globally with
`options(datadiff.lang = "en", datadiff.locale = "en_US")`). You can change
the language per call or globally for a session.

### Per call
Expand Down
Loading