Learn R Programming

⚠️There's a newer version (0.10.0) of this package.Take me there.

chk

chk is an R package for developers to check user-supplied function arguments.

It is designed to be simple, customizable and fast.

Installation

To install the latest development version from GitHub

# install.packages("remotes")
remotes::install_github("poissonconsulting/chk")

To install the latest developmental release from the Poisson drat repository

# install.packages("drat")
drat::addRepo("poissonconsulting")
install.packages("chk")

Demonstration

chk provides simple commonly used checks as (chk_ functions) which can be combined together for more complex checking.

library(chk)

y <- "a"

chk_string(y)
chk_flag(y)
#> `y` must be a flag (TRUE or FALSE).

chkor(chk_flag(y), chk_number(y))
#> At least one of the following conditions must be met:
#> * `y` must be a flag (TRUE or FALSE).
#> * `y` must be a number (non-missing numeric scalar).

data <- data.frame(x = 1:2)
chk_range(nrow(data), c(3,8))
#> `nrow(data)` must be between 3 and 8, not 2.

Error messages follow the tidyverse style guide while the errors themselves are rlang errors of subclass chk_error.

Information

For more information see the Get Started vignette.

Inspiration

Contribution

Please report any issues.

Pull requests are always welcome.

Please note that this project is released with a Contributor Code of Conduct. By contributing, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('chk')

Monthly Downloads

19,703

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Thorley

Last Published

November 15th, 2019

Functions in chk (0.2.0)

chk_equal

Check Equal
chk_false

Check FALSE
chk_numeric

Check Numeric
chk_ext

Check File Extension
chk_number

Check Number
chk_not_any_na

Check Not Any Missing Values
chk_datetime

Check DateTime
chk_not_empty

Check Not Empty
chk_deprecated

Deprecated functions
chk_dir

Check Directory Exists
chk_all_equal

Check All Equal
chk_unused

Check/Validate ... Unused or Used
chk_lgl

Check Logical Scalar
chk_identical

Check Identical
chk_unique

Check/Validate Unique
chk_environment

Check Environment
chk_not_null

Check not NULL
chk_file

Check File or Directory Exist
chk_flag

Check Flag
chk_equivalent

Check Equivalent
chk_range

Check/Validate Range
chk_true

Check TRUE
chk_whole_number

Check Whole Number
chkor

Check OR
chk_string

Check/Validate String or Matches
chk_null

Check NULL
chk_subset

Check/Validate Superset and Subset
err

Stop, Warning and Message Messages
chk_setequal

Check Set Equal
deparse_backtick

Deparse Backtick
message_chk

Construct Tidyverse Style Message
p

Concatenate Strings
chk_type

Check Type
vld

Validators
abort_chk

Abort Check
chk_date

Check Date
cc

Concatenate with Commas
chk_atomic

Check Atomic
aaa

Workaround: Avoid backtraces in examples
chk_all

Check All
chk-package

chk: Check User-Supplied Function Arguments
chk_all_equivalent

Check All Equivalent
chk_all_identical

Check All Identical