Skip to contents

After performing a join, use this function to understand why the row count changed. It analyzes the original tables and the result to explain the difference.

Usage

join_explain(result, x, y, by, type = NULL)

Arguments

result

The result of a join operation.

x

The original left data frame.

y

The original right data frame.

by

A character vector of column names used in the join.

type

Character. The type of join that was performed. One of "left", "right", "inner", "full". If NULL (default), attempts to infer the join type from row counts.

Value

Invisibly returns a list with explanation details. Prints a human-readable explanation.

Examples

orders <- data.frame(id = c(1, 2, 2, 3), value = 1:4)
customers <- data.frame(id = c(1, 2, 2, 4), name = c("A", "B1", "B2", "D"))

result <- merge(orders, customers, by = "id", all.x = TRUE)

# Explain why we got more rows than expected
join_explain(result, orders, customers, by = "id", type = "left")