R/safe_left_join.R
safe_left_join.Rd
Perform a "safe" left join where it is guaranteed that no additional rows are
added to the left hand side table. For more information on left joins see
(dplyr::left_join
).
safe_left_join(..., action = "error", relationship = "*:1")
... | Arguments passed on to
|
---|---|
action | What should happen when the number of rows changes from a join? Options include: 'error', 'warning', or 'message'. By default 'error'. |
relationship | What is the expected relationship between `x` and `y`? At this time the only available option is '*:1', indicating a many to one relationship between `x` and `y`. In the future more options may be added. |
An object of the same type as `x`. The order of the rows and columns of `x` is preserved as much as possible. The output has the following properties:
# The relationship between `x` and `y` is '*:1'. No extra rows will be added # to the left hand side. x <- data.frame(key = c("a", "a", "b"), value_x = c(1, 4, 2)) y <- data.frame(key = c("a", "b"), value_y = c(1, 1)) safe_left_join(x, y)#>#> key value_x value_y #> 1 a 1 1 #> 2 a 4 1 #> 3 b 2 1# The relationship between `x` and `y` is '1:*'. An error should be raised # because additional rows will be added to the left hand side. x <- data.frame(key = c("a", "b"), value_x = c(1, 2)) y <- data.frame(key = c("a", "a"), value_y = c(1, 1)) safe_left_join(x, y)#>#> Error in safe_left_join(x, y): Input data x had 2 rows. After performing the join the data has 3 rows.# Alternatively instead of raising an error a warning or message can be # outputted. x <- data.frame(key = c("a", "b"), value_x = c(1, 2)) y <- data.frame(key = c("a", "a"), value_y = c(1, 1)) safe_left_join(x, y, action = "warning")#>#> Warning: Input data x had 2 rows. After performing the join the data has 3 rows.#> key value_x value_y #> 1 a 1 1 #> 2 a 1 1 #> 3 b 2 NAsafe_left_join(x, y, action = "message")#>#>#> key value_x value_y #> 1 a 1 1 #> 2 a 1 1 #> 3 b 2 NA