knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) options(rlang_backtrace_on_error = "none")
The goal of declair is to provide standardized validation functions. It is inspired by vctrs::vec_assert()
and motivated by frustration and duplication across packages when validating user input.
You can install the released version of declair from CRAN with:
# no you cannot install.packages("declair")
devtools::install_github("DavisVaughan/declair")
library(declair)
Nice error messages based on type
dclr_is_character(1)
Expressions are auto labeled
x <- 1 dclr_is_character(x)
Works with function arguments
fn <- function(my_arg) { dclr_is_scalar_character(my_arg) } fn(x) fn(c("x", "y"))
Lots of extra helpers based on rlang goodies
dclr_has_name(mtcars, "x")
dclr_is_integerish(1.5) dclr_is_integerish(1) dclr_is_bool(1)
Combine multiple checks with dclr_or()
and dclr_and()
x <- 1L # All good because the second condition passes dclr_or(dclr_is_character(x), dclr_is_integer(x)) # This fails and tells you which condition caused the issue dclr_and(dclr_is_character(x), dclr_is_integer(x)) # This fails because neither pass dclr_or(dclr_is_character(x), dclr_has_name(x, "a name"))
dclr_or()
is particularly useful if an argument defaults to NULL
but can be other things.
x <- NULL # All good dclr_or(dclr_is_character(x), dclr_is_null(x)) x <- "hi" # All good dclr_or(dclr_is_character(x), dclr_is_null(x)) # Not good! x <- TRUE dclr_or(dclr_is_character(x), dclr_is_null(x))
You can use dclr()
on any custom ptype and size.
dclr(1, ptype = glue::glue(), size = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.