get_all_differences: Extract All Differences as a Unified Data Frame

View source: R/compare_datasets.R

get_all_differencesR Documentation

Extract All Differences as a Unified Data Frame

Description

Converts per-variable observation differences into a single long-format data frame suitable for filtering with dplyr, writing to CSV, or programmatic analysis. This is the R equivalent of SAS PROC COMPARE's OUT= dataset with _TYPE_ and _DIF_ variables.

Accepts output from compare_datasets(), cdisc_compare(), or any list containing an observation_comparison element with the standard discrepancies / details / id_details structure.

Usage

get_all_differences(comparison_results)

Arguments

comparison_results

A dataset_comparison or cdisc_comparison object, or any list with an observation_comparison element.

Value

A data frame with one row per differing cell. Columns:

Variable

Character: column name where the difference was found.

Row

Integer: row index in df1 (positional matching).

Base

The value in df1 (base dataset).

Compare

The value in df2 (compare dataset).

Diff

Numeric: Base - Compare (NA for character columns).

PctDiff

Numeric: absolute percentage difference relative to Base (NA when Base is 0 or column is character).

When key-based matching was used (id_vars), the ID columns are prepended to the left of the data frame.

Returns an empty data frame with the expected columns when no differences exist or observation comparison was skipped.

Examples


df1 <- data.frame(id = 1:3, value = c(10, 20, 30), name = c("A", "B", "C"))
df2 <- data.frame(id = 1:3, value = c(10, 25, 30), name = c("A", "B", "D"))
result <- compare_datasets(df1, df2)
diffs <- get_all_differences(result)
head(diffs)


clinCompare documentation built on Feb. 19, 2026, 1:07 a.m.