Examples for 'rlang::check_exclusive'


Check that arguments are mutually exclusive

Aliases: check_exclusive

Keywords:

### ** Examples

f <- function(x, y) {
  switch(
    check_exclusive(x, y),
    x = message("`x` was supplied."),
    y = message("`y` was supplied.")
  )
}

# Supplying zero or multiple arguments is forbidden
try(f())
Error in f() : One of `x` or `y` must be supplied.
try(f(NULL, NULL))
Error in f(NULL, NULL) : Exactly one of `x` or `y` must be supplied.
# The user must supply one of the mutually exclusive arguments
f(NULL)
`x` was supplied.
f(y = NULL)
`y` was supplied.
# With `.require` you can allow zero arguments
f <- function(x, y) {
  switch(
    check_exclusive(x, y, .require = FALSE),
    x = message("`x` was supplied."),
    y = message("`y` was supplied."),
    message("No arguments were supplied")
  )
}
f()
No arguments were supplied

[Package rlang version 1.1.4 Index]