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

13,635

Version

0.10.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Joe Thorley

Last Published

January 24th, 2025

Functions in chk (0.10.0)

chk_all_identical

Check All Identical
chk_character_or_factor

Check Character or Factor
check_values

Check Values and Class
chk-package

chk: Check User-Supplied Function Arguments
chk_date

Check Date
chk_date_time

Check Date Time
chk_equivalent

Check Equivalent
chk_dbl

Check Double Scalar
chk_deprecated

Deprecated functions
chk_dir

Check Directory Exists
chk_factor

Check Factor
chk_false

Check FALSE
chk_double

Check Double
chk_all_equal

Check All Equal
chk_ext

Check File Extension
chk_atomic

Check Atomic
chk_complex

Check Complex
chk_complex_number

Check Complex Number
chk_lgl

Check Logical Scalar
chk_data

Check Data
chk_count

Check Count
chk_gt

Check Greater Than
chk_match

Check Matches
chk_gte

Check Greater Than or Equal To
chk_matrix

Check Matrix
chk_list

Check List
chk_function

Check Function
chk_file

Check File Exists
chk_lte

Check Less Than or Equal To
chk_join

Check Join
chk_identical

Check Identical
chk_named

Check Named
chk_number

Check Number
chk_chr

Check Character Scalar
chk_missing

Check Missing Argument
chk_orderset

Check Set Ordered
chk_compatible_lengths

Check Compatible Lengths
chk_environment

Check Environment
chk_range

Checks range of non-missing values
chk_sorted

Check Sorted
chk_whole_number

Check Whole Number
vld_orderset

Check Set Equal
chk_whole_numeric

Check Whole Numeric
chk_length

Check Length
chk_raw

Check Raw
chk_s3_class

Check Type
message_chk

Construct Tidyverse Style Message
chk_numeric

Check Numeric
chk_flag

Check Flag
chk_valid_name

Check Valid Name
err

Stop, Warning and Message Messages
chk_vector

Check Vector
expect_chk_error

Expect Chk Error
chk_s4_class

Check Inherits from S4 Class
chk_scalar

Check Scalar
chkor_vld

Chk OR
p

Concatenate Strings
deparse_backtick_chk

Deparse Backtick
chk_not_any_na

Check Not Any Missing Values
chk_null

Check NULL
chk_null_or

Check NULL Or
chk_string

Check String
chkor

Check OR
vld_not_subset

Check Subset
chk_wnum

Check Whole Numeric Scalar
chk_integer

Check Integer
chk_equal

Check Equal
chk_unused

Check ... Unused
chk_not_null

Check not NULL
chk_lt

Check Less Than
chk_not_subset

Check Not Subset
chk_logical

Check Logical
chk_tz

Check Time Zone
chk_unique

Check Unique
chk_is

Check Class
chk_used

Check ... Used
chk_not_empty

Check Not Empty
chk_not_missing

Check Not Missing Argument
chk_true

Check TRUE
chk_superset

Check Superset
params

Parameter Descriptions for chk Package
aaa

Workaround: Avoid backtraces in examples
check_data

Check Data
abort_chk

Abort Check
check_key

Check Key
check_files

Check Files Exist
check_dirs

Check Directories Exist
check_names

Check Names
cc

Concatenate with Commas
check_length

Check Length
check_dim

Check Dimension
chk_all

Check All
chk_all_equivalent

Check All Equivalent
chk_array

Check Array
chk_character

Check Character