Learn R Programming

lares (version 4.10.6)

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, opts, type = "all", not = "stop", quiet = TRUE)

Arguments

inputs

Vector character

opts

Vector character

type

Character. Options: all, any

not

Character. Options: stop, message, print, return

quiet

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

Value

Boolean. Result of inputs in opts (options). Depending on type and/or stop arguments, errors or messages will be shown.

Examples

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

Run the code above in your browser using DataLab