valid | R Documentation |
Designed to be called inside a customvalid_*
function (e.g. valid_yes_no()
)
valid( choice = character(), choices = character(), reverse = FALSE, flip = FALSE, strict = TRUE, unname = FALSE, call = sys.call(-1)[[1]] )
choice |
(character) Available values |
choices |
(character) Selection of available values |
reverse |
(logical) Reverse order yes/no |
flip |
(logical) Flip names and values yes/no |
strict |
(logical) Be strict about "things that might go wrong" yes/no |
unname |
(logical) Drop names yes/no |
call |
(call) Enclosing call |
valid_foo <- function( choice = character(), ... ) { choices <- letters[1:3] names(choices) <- choices %>% toupper() valid::valid( choice = choice, choices = choices, ... ) } valid_foo() # Via name valid_foo("A") valid_foo("A", "C") # Via value valid_foo("a") valid_foo("a", "c") # Handling obvious errors try(valid_foo("D")) try(valid_foo("d")) # Handling partial errors try(valid_foo("A", "D")) try(valid_foo("A", "D", .strict = FALSE)) try(valid_foo("a", "d")) try(valid_foo("a", "d", .strict = FALSE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.