left_join_check: left_join augmented with checks

Description Usage Arguments Examples

View source: R/safer_joins.R

Description

This augments left_join from the dplyr package with important quality control checks. When by is not NULL, then it checks for duplicated IDs (e.g., join variables). When by is NULL, if there is only one column in common between x and y, then it checks for duplicated IDs using that single column as the join variable. Also checks if the resulting join has more records than the input table x.

Usage

1
2
left_join_check(x, y, by = NULL, copy = FALSE, suffix = c(".x",
  ".y"), ...)

Arguments

x

table to left join into.

y

table to be joined into x.

by

a character vector of variables to join by.

copy

If x and y are not from the same data source, and copy is TRUE, then y will be copied into the same src as x.

suffix

If there are non-joined duplicate variables in x and y, these suffixes will be added to the output to disambiguate them. Should be a character vector of length 2.

Examples

1
2
3
4
5
6
7
8
x <- data.frame(ID=c(1,2,3),ID1=c(1,2,3),x=c(1,1,1))
y <- data.frame(ID=c(1,2,2),ID2=c(1,2,2),y=c(2,2,2))
x
y
left_join_check(x,y)
left_join_check(x,y,by="ID")
left_join_check(x,y,by = c("ID" = "ID"))
left_join_check(x,y,by = c("ID1" = "ID2"))

DanielEWeeks/dweeks documentation built on Dec. 8, 2019, 8 a.m.