Learn R Programming

chk

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

It is designed to be simple, customizable and fast.

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).

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

Or used inside functions to test user-provided arguments.

my_fun <- function(x) {
  chk_flag(x)
  x
}
my_fun(TRUE)
#> [1] TRUE
my_fun(NA)
#> Error in `my_fun()`:
#> ! `x` must be a flag (TRUE or FALSE).

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

Information

For more information see the Get Started vignette.

Installation

Release

To install the release version from CRAN.

install.packages("chk")

The website for the release version is at https://poissonconsulting.github.io/chk/.

Development

To install the development version from GitHub

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

or from r-universe.

install.packages("chk", repos = c("https://poissonconsulting.r-universe.dev", "https://cloud.r-project.org"))

Inspiration

Contribution

Please report any issues.

Pull requests are always welcome.

Code of Conduct

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

Copy Link

Version

Install

install.packages('chk')

Monthly Downloads

14,704

Version

0.11.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Thorley

Last Published

September 3rd, 2026

Functions in chk (0.11.0)

chk-package

chk: Check User-Supplied Function Arguments
chk_complex_number

Check Complex Number
chk_atomic

Check Atomic
chk_all_identical

Check All Identical
chk_double

Check Double
chk_date_time

Check Date Time
chk_file

Check File Exists
chk_character

Check Character
chk_date

Check Date
chk_dir

Check Directory Exists
chk_flag

Check Flag
chk_equal

Check Equal
chk_gt

Check Greater Than
chk_chr

Check Character Scalar
chk_function

Check Function
chk_character_or_factor

Check Character or Factor
chk_environment

Check Environment
chk_missing

Check Missing Argument
chk_matrix

Check Matrix
chk_lte

Check Less Than or Equal To
chk_not_empty

Check Not Empty
chk_match

Check Matches
chk_not_missing

Check Not Missing Argument
chk_dbl

Check Double Scalar
chk_count

Check Count
chk_deprecated

Deprecated functions
chk_false

Check FALSE
chk_factor

Check Factor
chk_data

Check Data
chk_range

Checks range of non-missing values
chk_raw

Check Raw
chk_named

Check Named
chk_join

Check Join
chk_length

Check Length
chk_compatible_lengths

Check Compatible Lengths
chk_equivalent

Check Equivalent
chk_ext

Check File Extension
chk_class

Check Type
chk_not_subset

Check Not Subset
chk_string

Check String
chk_lgl

Check Logical Scalar
chk_list

Check List
chk_integer

Check Integer
chk_not_null

Check not NULL
chk_not_any_na

Check Not Any Missing Values
chk_numeric

Check Numeric
chk_s4_class

Check Inherits from S4 Class
chk_number

Check Number
chk_orderset

Check Set Ordered
chk_is

Check Class
chk_gte

Check Greater Than or Equal To
chk_setequal

Check Set Equal
chk_superset

Check Superset
chk_logical

Check Logical
chk_lt

Check Less Than
chk_sorted

Check Sorted
chkor_vld

Chk OR
deparse_backtick_chk

Deparse Backtick
chk_true

Check TRUE
chk_wnum

Check Whole Numeric Scalar
chkor

Check OR
chk_null

Check NULL
chk_valid_name

Check Valid Name
chk_vector

Check Vector
chk_r6_class

Check Inherits from R6 Class
chk_identical

Check Identical
chk_tz

Check Time Zone
chk_whole_number

Check Whole Number
chk_s3_class_strict

Check Type
chk_s3_class

Check Type
chk_subset

Check Subset
chk_whole_numeric

Check Whole Numeric
chk_null_or

Check NULL Or
chk_scalar

Check Scalar
err

Stop, Warning and Message Messages
chk_unused

Check ... Unused
expect_chk_error

Expect Chk Error
chk_used

Check ... Used
params

Parameter Descriptions for chk Package
p

Concatenate Strings
generate_check_data

Generate check_data() Code
message_chk

Construct Tidyverse Style Message
chk_unique

Check Unique
check_length

Check Length
check_files

Check Files Exist
aaa

Workaround: Avoid backtraces in examples
cc

Concatenate with Commas
check_names

Check Names
check_data

Check Data
check_dim

Check Dimension
check_key

Check Key
abort_chk

Abort Check
check_dirs

Check Directories Exist
chk_all

Check All
chk_all_equivalent

Check All Equivalent
chk_array

Check Array
chk_all_equal

Check All Equal
check_values

Check Values and Class
chk_all_na

Check All Missing Values
chk_complex

Check Complex