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 release from CRAN

install.packages("pkgtemplate")

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)
#> Error: `y` must be a flag (TRUE or FALSE).

chkor(chk_flag(y), chk_number(y))
#> Error: 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))
#> Error: `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

20,056

Version

0.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Thorley

Last Published

March 4th, 2020

Functions in chk (0.4.0)

check_values

Check Values and Class
chk_all_equal

Check All Equal
chk_all_identical

Check All Identical
chk_lt

Check Less Than
chk_equivalent

Check Equivalent
chk_data

Check Data
chk_all_equivalent

Check All Equivalent
chk_matrix

Check Matrix
chk_ext

Check File Extension
chk_match

Check Matches
chk_lte

Check Less Than or Equal To
chk_atomic

Check Atomic
chk_array

Check Array
chk_superset

Check Superset
chk_used

Check ... Used
chk_subset

Check Subset
chk_datetime

Check DateTime
chk_vector

Check Vector
chk_environment

Check Environment
chk_s3_class

Check Type
chk_identical

Check Identical
chk_integer

Check Integer
chk_numeric

Check Numeric
params

Parameters for chk functions
chk_character

Check Character
chk_range

Checks range of non-missing values
chk_equal

Check Equal
chk_list

Check List
chk_flag

Check Flag
chk_logical

Check Logical
chk_function

Check Function
chk_date

Check Date
chk_s4_class

Check Inherits from S4 Class
chk_false

Check FALSE
chk_null

Check NULL
chk_scalar

Check Scalar
chk_number

Check Number
chk_dir

Check Directory Exists
chk_gt

Check Greater Than
chk_double

Check Double
chk_setequal

Check Set Equal
chk_gte

Check Greater Than or Equal To
chk_deprecated

Deprecated functions
chk_file

Check File Exists
chkor

Check OR
chk_not_any_na

Check Not Any Missing Values
chk_string

Check String
chk_named

Check Named
chk_whole_numeric

Check Whole Numeric
chk_sorted

Check Sorted
chk_whole_number

Check Whole Number
chk_lgl

Check Logical Scalar
chk_join

Check Join
deparse_backtick_chk

Deparse Backtick
chk_not_empty

Check Not Empty
chk_not_null

Check not NULL
chk_tz

Check Time Zone
chk_true

Check TRUE
p

Concatenate Strings
message_chk

Construct Tidyverse Style Message
chk_unique

Check Unique
expect_chk_error

Expect Chk Error
err

Stop, Warning and Message Messages
chk_unused

Check ... Unused
cc

Concatenate with Commas
check_data

Check Data
check_names

Check Names
check_dim

Check Dimension
check_key

Check Key
abort_chk

Abort Check
aaa

Workaround: Avoid backtraces in examples
chk_all

Check All
chk-package

chk: Check User-Supplied Function Arguments