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.

Installation

To install the latest release from CRAN

install.packages("chk")

To install the latest development version from GitHub

# install.packages("remotes")
remotes::install_github("poissonconsulting/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).

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.

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

16,251

Version

0.9.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 9th, 2024

Functions in chk (0.9.2)

chk_date_time

Check Date Time
chk_all

Check All
chk_data

Check Data
chk_gte

Check Greater Than or Equal To
chk_ext

Check File Extension
chk_date

Check Date
chk_gt

Check Greater Than
chk_dbl

Check Double Scalar
chk_factor

Check Factor
chk_equivalent

Check Equivalent
chk_integer

Check Integer
chk_equal

Check Equal
chk_list

Check List
chk_identical

Check Identical
chk_logical

Check Logical
chk_flag

Check Flag
chk_double

Check Double
chk_null

Check NULL
chk_function

Check Function
chk_environment

Check Environment
chk_deprecated

Deprecated functions
chk_not_subset

Check Not Subset
chk_length

Check Length
chk_false

Check FALSE
chk_dir

Check Directory Exists
chk_file

Check File Exists
chk_missing

Check Missing Argument
chk_named

Check Named
chk_orderset

Check Set Ordered
chk_numeric

Check Numeric
chk_match

Check Matches
chk_lgl

Check Logical Scalar
chk_number

Check Number
chk_whole_number

Check Whole Number
chk_null_or

Check NULL Or
chk_matrix

Check Matrix
chk_whole_numeric

Check Whole Numeric
vld_not_subset

Check Subset
chk_not_any_na

Check Not Any Missing Values
vld_orderset

Check Set Equal
chk_not_empty

Check Not Empty
chk_string

Check String
chk_sorted

Check Sorted
chk_count

Check Count
chk_compatible_lengths

Check Compatible Lengths
chk_unused

Check ... Unused
chk_s4_class

Check Inherits from S4 Class
chk_join

Check Join
chk_tz

Check Time Zone
chk_superset

Check Superset
chk_is

Check Class
chk_scalar

Check Scalar
chk_lt

Check Less Than
chk_used

Check ... Used
chkor

Check OR
chkor_vld

Chk OR
chk_valid_name

Check Valid Name
chk_s3_class

Check Type
chk_lte

Check Less Than or Equal To
err

Stop, Warning and Message Messages
chk_wnum

Check Whole Numeric Scalar
chk_not_missing

Check Not Missing Argument
chk_not_null

Check not NULL
chk_range

Checks range of non-missing values
chk_vector

Check Vector
chk_true

Check TRUE
chk_unique

Check Unique
expect_chk_error

Expect Chk Error
deparse_backtick_chk

Deparse Backtick
message_chk

Construct Tidyverse Style Message
p

Concatenate Strings
params

Parameters for chk functions
abort_chk

Abort Check
check_dim

Check Dimension
check_dirs

Check Directories Exist
cc

Concatenate with Commas
check_files

Check Files Exist
check_key

Check Key
check_values

Check Values and Class
check_names

Check Names
check_data

Check Data
aaa

Workaround: Avoid backtraces in examples
chk-package

chk: Check User-Supplied Function Arguments
chk_atomic

Check Atomic
chk_character

Check Character
chk_all_equal

Check All Equal
chk_array

Check Array
chk_chr

Check Character Scalar
chk_character_or_factor

Check Character or Factor
chk_all_identical

Check All Identical
chk_all_equivalent

Check All Equivalent