Learn R Programming

lares (version 4.8.4)

check_opts: Validate options within vector

Description

This function validates if inputs match all/any of your options and return error/message with possible options to use.

Usage

check_opts(inputs, options, type = "all", not = "stop", quiet = TRUE)

Arguments

inputs

Vector character

options

Vector character

type

Character. Options: all, any

not

Character. Options: stop, message, print, return

quiet

Boolean. Keep quiet? If not, returns TRUE or FALSE

Examples

Run this code
# NOT RUN {
options <- c("A", "B", "C")
# Let's check the "all" logic
check_opts(inputs = c("A", "B"), options, quiet = FALSE)
check_opts(inputs = c("X"), options, not = "message", quiet = FALSE)
check_opts(inputs = c("A","X"), options, not = "warning")
# Now let's check the "any" logic
check_opts(inputs = c("A","X"), options, type = "any")
check_opts(inputs = c("X"), options, type = "any", not = "message")
check_opts(inputs = c("A", NA), options, type = "any")
# Final trick: just ignore results
check_opts(inputs = "X", options, not = "invisible")
# }

Run the code above in your browser using DataLab