safe.mapping: Maps with a left_join, ensuring constant number of rows

Description Usage Arguments Examples

View source: R/safe.mapping.R

Description

This avoids generating left duplicates if entries are duplicated in the right by. If duplicates are generated, the function will stop with an error.

Usage

1
safe.mapping(x, map, by = NULL)

Arguments

x

the data.frame with fixed size

map

a data.frame with the new columns.

by

see left_join

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
a <- data.frame(A = LETTERS[1:5], B = 1:5)
b <- data.frame(A = LETTERS[1:5], C = 15:11)
dplyr::left_join(a, b)
safe.mapping(a, b)

# Now with duplicates
## Not run: 
c <- data.frame(A = LETTERS[1:5], C = 20:11)
dplyr::left_join(a, c) # creates duplicates of x
safe.mapping(a, c) # stops with an error

## End(Not run)

xrobin/xavamess documentation built on June 15, 2021, 3:46 a.m.