safe_left_join {safejoin} | R Documentation |
Validate extra rows are added not added to the left hand side
Description
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
).
Usage
safe_left_join(..., action = "error", relationship = "*:1")
Arguments
... |
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 |
Value
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:
Examples
# 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)
# The relationship between `x` and `y` is '1:*'. An error should be raised
# because additional rows will be added to the left hand side.
## Not run: 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)
## End(Not run)
# 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")
safe_left_join(x, y, action = "message")