Movatterモバイル変換


[0]ホーム

URL:


Title:Check User-Supplied Function Arguments
Version:0.10.0
Description:For developers to check user-supplied function arguments. It is designed to be simple, fast and customizable. Error messages follow the tidyverse style guide.
License:MIT + file LICENSE
URL:https://github.com/poissonconsulting/chk,https://poissonconsulting.github.io/chk/
BugReports:https://github.com/poissonconsulting/chk/issues/
Depends:R (≥ 3.6)
Imports:lifecycle, methods, rlang, tools
Suggests:covr, knitr, rmarkdown, testthat (≥ 3.0.0), withr
VignetteBuilder:knitr
RdMacros:lifecycle
Config/Needs/website:poissonconsulting/poissontemplate
Config/testthat/edition:3
Encoding:UTF-8
Language:en-US
RoxygenNote:7.3.2.9000
NeedsCompilation:no
Packaged:2025-01-24 19:31:20 UTC; joe
Author:Joe ThorleyORCID iD [aut, cre], Kirill MüllerORCID iD [aut], Ayla PearsonORCID iD [aut], Florencia D'Andrea [ctb], Nadine HusseinORCID iD [ctb], Evan Amies-GalonskiORCID iD [ctb], Poisson Consulting [cph, fnd]
Maintainer:Joe Thorley <joe@poissonconsulting.ca>
Repository:CRAN
Date/Publication:2025-01-24 21:20:05 UTC

chk: Check User-Supplied Function Arguments

Description

logo

For developers to check user-supplied function arguments. It is designed to be simple, fast and customizable. Error messages follow the tidyverse style guide.

Author(s)

Maintainer: Joe Thorleyjoe@poissonconsulting.ca (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Workaround: Avoid backtraces in examples

Description

This example will run first and set the option for the process that buildsthe example.(By default, pkgdown builds in a separate process.)This also produces a help page that isn't linked from anywhere.

Examples

options(rlang_backtrace_on_error = "none")

Abort Check

Description

A wrapper onerr() that sets the subclass to be'chk_error'.

Usage

abort_chk(..., n = NULL, tidy = TRUE, call = rlang::caller_call(2))

Arguments

...

Multiple objects that are converted to a string usingpaste0(..., collapse = '').

n

The value of n for convertingsprintf-like types.

tidy

A flag specifying whether capitalize the first character and add a missing period.

call

The execution environment of a currently runningfunction, e.g.call = caller_env(). The corresponding functioncall is retrieved and mentioned in error messages as the sourceof the error.

You only need to supplycall when throwing a condition from ahelper function which wouldn't be relevant to mention in themessage.

Can also beNULL or adefused function call torespectively not display any call or hard-code a code to display.

For more information about error calls, seeIncluding function calls in error messages.

Details

It is exported to allow users to easily construct their ownchk_ functions.

Value

Throws an error of class'chk_error'.

See Also

err()

Examples

try(abort_chk("x must be NULL"))try(abort_chk("`x` must be NULL"))try(abort_chk("there %r %n problem value%s", n = 1))try(abort_chk("there %r %n problem value%s", n = 1.5))

Concatenate with Commas

Description

Concatenates object values into a string with each value separated by a commaand the last value separated by a conjunction.

Usage

cc(  x,  conj = ", ",  sep = ", ",  brac = if (is.character(x) || is.factor(x)) "'" else "",  ellipsis = 10L,  chk = TRUE)

Arguments

x

The object to concatenate.

conj

A string of the conjunction to separate the last value by.

sep

A string of the separator.

brac

A string to brac the values by.

ellipsis

A numeric scalar of the maximum number of values to displaybefore using an ellipsis.

chk

A flag specifying whether to check the other parameters.

Details

By default, if x has more than 10 values an ellipsis is usedto ensure only 10 values are displayed (including the ellipsis).

Value

A string.

Examples

cc(1:2)cc(1:2, conj = " or")cc(3:1, brac = "'")cc(1:11)cc(as.character(1:2))

Check Data

Description

Checks column names, values, number of rows and key for a data.frame.

Usage

check_data(  x,  values = NULL,  exclusive = FALSE,  order = FALSE,  nrow = numeric(0),  key = character(0),  x_name = NULL)

Arguments

x

The object to check.

values

A uniquely named list of atomic vectors of the column values.

exclusive

A flag specifying whether x must only include columns named in values.

order

A flag specifying whether the order of columns in x must match names in values.

nrow

A flag or a whole numeric vector of the value, value range or possible values.

key

A character vector of the columns that represent a unique key.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_dim(),check_dirs(),check_files(),check_key(),check_length(),check_names(),check_values()

Examples

check_data(data.frame())check_data(data.frame(x = 2), list(x = 1))try(check_data(data.frame(x = 2), list(y = 1L)))try(check_data(data.frame(x = 2), list(y = 1)))try(check_data(data.frame(x = 2), nrow = 2))

Check Dimension

Description

Checks dimension of an object.

Usage

check_dim(x, dim = length, values = numeric(0), x_name = NULL, dim_name = NULL)

Arguments

x

The object to check.

dim

A function returning a non-negative whole number of the dimension.

values

A flag or a whole numeric vector of the value, value range or possible values.

x_name

A string of the name of object x or NULL.

dim_name

A string of the name of the dim function.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dirs(),check_files(),check_key(),check_length(),check_names(),check_values()

Examples

check_dim(1)try(check_dim(1, values = FALSE))try(check_dim(1, values = c(10, 2)))try(check_dim(data.frame(x = 1), dim = nrow, values = c(10, 10, 2)))

Check Directories Exist

Description

Checks if all directories exist (or if exists = FALSE do not exist as directories or files).

Usage

check_dirs(x, exists = TRUE, x_name = NULL)

Arguments

x

The object to check.

exists

A flag specifying whether the files/directories must (or must not) exist.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_files(),check_key(),check_length(),check_names(),check_values()

Examples

check_dirs(tempdir())try(check_dirs(tempdir(), exists = FALSE))

Check Files Exist

Description

Checks if all files exist (or if exists = FALSE do not exist as files or directories).

Usage

check_files(x, exists = TRUE, x_name = NULL)

Arguments

x

The object to check.

exists

A flag specifying whether the files/directories must (or must not) exist.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_dirs(),check_key(),check_length(),check_names(),check_values()

Examples

check_files(tempfile("unlikely-that-exists-chk"), exists = FALSE)try(check_files(tempfile("unlikely-that-exists-chk")))

Check Key

Description

Checks if columns have unique rows.

Usage

check_key(x, key = character(0), na_distinct = FALSE, x_name = NULL)

Arguments

x

The object to check.

key

A character vector of the columns that represent a unique key.

na_distinct

A flag specifying whether missing values should be considered distinct.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_dirs(),check_files(),check_length(),check_names(),check_values()

Examples

x <- data.frame(x = c(1, 2), y = c(1, 1))check_key(x)try(check_key(x, "y"))

Check Length

Description

Checks length of an object.

Usage

check_length(x, values = numeric(0), x_name = NULL)

Arguments

x

The object to check.

values

A flag or a whole numeric vector of the value, value range or possible values.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_dirs(),check_files(),check_key(),check_names(),check_values()

Examples

check_length(1)try(check_length(1, values = FALSE))try(check_length(1, values = c(10, 2)))

Check Names

Description

Checks the names of an object.

Usage

check_names(  x,  names = character(0),  exclusive = FALSE,  order = FALSE,  x_name = NULL)

Arguments

x

The object to check.

names

A character vector of the required names.

exclusive

A flag specifying whether x must only contain the required names.

order

A flag specifying whether the order of the required names in x must match the order in names.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_dirs(),check_files(),check_key(),check_length(),check_values()

Examples

x <- c(x = 1, y = 2)check_names(x, c("y", "x"))try(check_names(x, c("y", "x"), order = TRUE))try(check_names(x, "x", exclusive = TRUE))

Check Values and Class

Description

Checks values and S3 class of an atomic object.

Usage

check_values(x, values, x_name = NULL)

Arguments

x

The object to check.

values

An atomic vector specifying the S3 class and possible values.

x_name

A string of the name of object x or NULL.

Details

To check the class simply pass a vector of the desired class.

To check that x does not include missing values passa single non-missing value (of the correct class).

To allow it to include missing values include a missing value.

To check that it only includes missing values only passa missing value (of the correct class).

To check the range of the values in x pass two non-missing values(as well as the missing value if required).

To check that x only includes specific valuespass three or more non-missing values.

In the case of a factor ensure values has two levels tocheck that the levels of x are an ordered superset of the levels of valueand three or more levels to check that they are identical.

Value

An informative error if the test fails or an invisible copy of x.

See Also

Other check:check_data(),check_dim(),check_dirs(),check_files(),check_key(),check_length(),check_names()

Examples

check_values(1, numeric(0))check_values(1, 2)try(check_values(1, 1L))try(check_values(NA_real_, 1))

Check All

Description

Checks all elements using

all(vapply(x, chk_fun, TRUE, ...))

Usage

chk_all(x, chk_fun, ..., x_name = NULL)vld_all(x, vld_fun, ...)

Arguments

x

The object to check.

chk_fun

A chk_ function.

...

Additional arguments.

x_name

A string of the name of object x or NULL.

vld_fun

A vld_ function.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other all_checkers:chk_all_equal(),chk_all_equivalent(),chk_all_identical()

Examples

# chk_allchk_all(TRUE, chk_lgl)# FIXME try(chk_all(1, chk_lgl))chk_all(c(TRUE, NA), chk_lgl)# vld_allvld_all(c(TRUE, NA), vld_lgl)

Check All Equal

Description

Checks all elements in x equal using

length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance))

Usage

chk_all_equal(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL)vld_all_equal(x, tolerance = sqrt(.Machine$double.eps))

Arguments

x

The object to check.

tolerance

A non-negative numeric scalar.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

vld_equal()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equivalent(),chk_all_identical(),chk_equal(),chk_equivalent(),chk_identical()

Other all_checkers:chk_all(),chk_all_equivalent(),chk_all_identical()

Examples

# chk_all_equalchk_all_equal(c(1, 1.00000001))try(chk_all_equal(c(1, 1.0000001)))chk_all_equal(list(c(x = 1), c(x = 1)))try(chk_all_equal(list(c(x = 1), c(y = 1))))# vld_all_equalvld_all_equal(c(1, 1L))

Check All Equivalent

Description

Checks all elements in x equivalent using

length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance))

Usage

chk_all_equivalent(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL)vld_all_equivalent(x, tolerance = sqrt(.Machine$double.eps))

Arguments

x

The object to check.

tolerance

A non-negative numeric scalar.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

vld_equivalent()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equal(),chk_all_identical(),chk_equal(),chk_equivalent(),chk_identical()

Other all_checkers:chk_all(),chk_all_equal(),chk_all_identical()

Examples

# chk_all_equivalentchk_all_equivalent(c(1, 1.00000001))try(chk_all_equivalent(c(1, 1.0000001)))chk_all_equivalent(list(c(x = 1), c(x = 1)))chk_all_equivalent(list(c(x = 1), c(y = 1)))# vld_all_equivalentvld_all_equivalent(c(x = 1, y = 1))

Check All Identical

Description

Checks all elements in x identical using

length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]]))

Pass:c(1, 1, 1),list(1, 1)

Fail:c(1, 1.0000001),list(1, NA)

Usage

chk_all_identical(x, x_name = NULL)vld_all_identical(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

vld_identical()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equal(),chk_all_equivalent(),chk_equal(),chk_equivalent(),chk_identical()

Other all_checkers:chk_all(),chk_all_equal(),chk_all_equivalent()

Examples

# chk_all_identicalchk_all_identical(c(1, 1))try(chk_all_identical(c(1, 1.1)))# vld_all_identicalvld_all_identical(c(1, 1))

Check Array

Description

Checks if is an array using

is.array(x)

Usage

chk_array(x, x_name = NULL)vld_array(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.array()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_structure_checkers:chk_atomic(),chk_list(),chk_matrix(),chk_vector()

Examples

# chk_arraychk_array(array(1))try(chk_array(matrix(1)))# vld_arrayvld_array(1)vld_array(array(1))

Check Atomic

Description

Checks if atomic using

is.atomic(x)

Usage

chk_atomic(x, x_name = NULL)vld_atomic(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.atomic()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_structure_checkers:chk_array(),chk_list(),chk_matrix(),chk_vector()

Examples

# chk_atomicchk_atomic(1)try(chk_atomic(list(1)))# vld_atomicvld_atomic(1)vld_atomic(matrix(1:3))vld_atomic(character(0))vld_atomic(list(1))vld_atomic(NULL)

Check Character

Description

Checks if character using

is.character(x)

Usage

chk_character(x, x_name = NULL)vld_character(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.character()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character_or_factor(),chk_complex(),chk_double(),chk_environment(),chk_integer(),chk_logical(),chk_numeric(),chk_raw()

Examples

# chk_characterchk_character("1")try(chk_character(1))# vld_charactervld_character("1")vld_character(matrix("a"))vld_character(character(0))vld_character(NA_character_)vld_character(1)vld_character(TRUE)vld_character(factor("text"))

Check Character or Factor

Description

Checks if character or factor using

is.character(x) || is.factor(x)

Usage

chk_character_or_factor(x, x_name = NULL)vld_character_or_factor(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.character()

is.factor()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_complex(),chk_double(),chk_environment(),chk_integer(),chk_logical(),chk_numeric(),chk_raw()

Other factor_checkers:chk_factor()

Examples

# chk_character_or_factorchk_character_or_factor("1")chk_character_or_factor(factor("1"))try(chk_character(1))# vld_character_or_factorvld_character_or_factor("1")vld_character_or_factor(matrix("a"))vld_character_or_factor(character(0))vld_character_or_factor(NA_character_)vld_character_or_factor(1)vld_character_or_factor(TRUE)vld_character_or_factor(factor("text"))

Check Character Scalar

Description

Checks if character scalar using

is.character(x) && length(x) == 1L

[Deprecated]

Usage

chk_chr(x, x_name = NULL)vld_chr(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

Other deprecated:chk_dbl(),chk_deprecated,chk_wnum()

Examples

chk_chr("a")try(chk_chr(1))# vld_chrvld_chr("")vld_chr("a")vld_chr(NA_character_)vld_chr(c("a", "b"))vld_chr(1)

Check Compatible Lengths

Description

Checks objects (including vectors) have lengths that could be 'strictlyrecycled'. That is to say they must all be either zero length or the samelength with some of length 1.

Usage

chk_compatible_lengths(..., x_name = NULL)vld_compatible_lengths(...)

Arguments

...

The objects to check for compatible lengths.

x_name

A string of the name of object x or NULL.

Details

This function helps to check vectors could be 'strictly recycled.'For example the function will error if you had a vector of length 2 andlength 4, even though the vector of length 2 could be 'loosely recycled' tomatch up to the vector of length 4 when combined.

The intent of the function is to check that only strict recycling isoccurring.

Value

Thechk_ function throws an informative error if the test fails.

Functions

See Also

For more details about the use of this function,please read the articlevignette("chk-families").

Other length_checkers:chk_length()

Examples

# chk_compatible_lengthsa <- integer(0)b <- numeric(0)chk_compatible_lengths(a, b)a <- 1b <- 2chk_compatible_lengths(a, b)a <- 1:3b <- 1:3chk_compatible_lengths(a, b)b <- 1chk_compatible_lengths(a, b)b <- 1:2try(chk_compatible_lengths(a, b))b <- 1:6try(chk_compatible_lengths(a, b))# vld_compatible_lengthsa <- integer(0)b <- numeric(0)vld_compatible_lengths(a, b)a <- 1b <- 2vld_compatible_lengths(a, b)a <- 1:3b <- 1:3vld_compatible_lengths(a, b)b <- 1vld_compatible_lengths(a, b)b <- 1:2vld_compatible_lengths(a, b)b <- 1:6vld_compatible_lengths(a, b)

Check Complex

Description

Checks if complex using

is.complex(x)

Usage

chk_complex(x, x_name = NULL)vld_complex(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.complex()

For more details about the use of this function,please read the articlechk families.

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_double(),chk_environment(),chk_integer(),chk_logical(),chk_numeric(),chk_raw()

Examples

# chk_complexchk_complex(1i)try(chk_complex(1))# vld_complexvld_complex(1i)vld_complex(complex())vld_complex(NA_complex_)vld_complex(1)vld_complex(TRUE)

Check Complex Number

Description

Checks if non-missing complex scalar using

is.complex(x) && length(x) == 1L && !anyNA(x)

Usage

chk_complex_number(x, x_name = NULL)vld_complex_number(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.integer()

vld_true()

vld_number()

For more details about the use of this function,please read the articlechk families.

Other scalar_checker:chk_whole_number()

Examples

# chk_complex_numberchk_complex_number(as.complex(1.1))try(chk_complex_number(1.1))# vld_complex_numbervld_complex_number(as.complex(2))

Check Count

Description

Checks if non-negative whole number using

vld_whole_number(x) && x >= 0

Usage

chk_count(x, x_name = NULL)vld_count(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_whole_number()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Other whole_number_checkers:chk_whole_number(),chk_whole_numeric()

Examples

# chk_countchk_count(1)try(chk_count(1.5))# vld_countvld_count(1)vld_count(0L)vld_count(-1)vld_count(0.5)

Check Data

Description

Checks data.frame using

inherits(x, "data.frame")

Note that there is a similar function,check_data(), which checksthe column names, values, number of rows, and keys of a data.frame.

Usage

chk_data(x, x_name = NULL)vld_data(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

inherits()

For more details about the use of this function,please read the articlevignette("chk-families").

Other id_checkers:chk_is(),chk_s3_class(),chk_s4_class()

Examples

# chk_datachk_data(data.frame(x = 1))try(chk_data(1))# vld_datavld_data(data.frame())vld_data(data.frame(x = 1))vld_data(c(x = 1))

Check Date

Description

Checks non-missing Date scalar using

inherits(x, "Date") && length(x) == 1L && !anyNA(x)

Usage

chk_date(x, x_name = NULL)vld_date(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

inherits()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_count(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Other datetime_checkers:chk_date_time()

Examples

# chk_datechk_date(Sys.Date())try(chk_date(1))# vld_datevld_date(Sys.Date())vld_date(Sys.time())vld_date(1)

Check Date Time

Description

Checks if non-missing POSIXct scalar using

inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)

Usage

chk_date_time(x, x_name = NULL)chk_datetime(x, x_name = NULL)vld_date_time(x)vld_datetime(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

inherits(),length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_count(),chk_date(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Other datetime_checkers:chk_date()

Examples

# chk_date_timechk_date_time(as.POSIXct("2001-01-02"))try(chk_date_time(1))# vld_date_timevld_date_time(as.POSIXct("2001-01-02"))vld_date_time(Sys.time())vld_date_time(1)vld_date_time("2001-01-02")vld_date_time(c(Sys.time(), Sys.time()))

Check Double Scalar

Description

Checks if double scalar using

is.double(x) && length(x) == 1L

[Deprecated]

Usage

chk_dbl(x, x_name = NULL)vld_dbl(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

Other deprecated:chk_chr(),chk_deprecated,chk_wnum()

Examples

# chk_dblchk_dbl(1)try(chk_dbl(1L))# vld_dblvld_dbl(1)vld_dbl(double(0))vld_dbl(NA_real_)vld_dbl(c(1, 1))vld_dbl(1L)

Deprecated functions

Description

Deprecatedchk_() functions.

Usage

chk_dirs(x)chk_files(x)chk_has(x, values, x_name = NULL)chk_in(x, values, x_name = NULL)chk_no_missing(x, x_name = NULL)vld_no_missing(x)chk_off()chk_on()is_chk_on()chk_proportion(x, x_name = NULL)deparse_backtick(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Functions

See Also

Other deprecated:chk_chr(),chk_dbl(),chk_wnum()


Check Directory Exists

Description

Checks if directory exists using

vld_string(x) && dir.exists(x)

Usage

chk_dir(x, x_name = NULL)vld_dir(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_string()

dir.exists()

For more details about the use of this function,please read the articlevignette("chk-families").

Other file_checkers:chk_ext(),chk_file()

Examples

# chk_dirchk_dir(tempdir())try(chk_dir(tempfile()))# vld_dirvld_dir(1)vld_dir(tempdir())vld_dir(tempfile())

Check Double

Description

Checks if double using

is.double(x)

Usage

chk_double(x, x_name = NULL)vld_double(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.double()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_environment(),chk_integer(),chk_logical(),chk_numeric(),chk_raw()

Examples

# chk_doublechk_double(1)try(chk_double(1L))# vld_doublevld_double(1)vld_double(matrix(c(1, 2, 3, 4), nrow = 2L))vld_double(double(0))vld_double(numeric(0))vld_double(NA_real_)vld_double(1L)vld_double(TRUE)

Check Environment

Description

Checks if environment using

is.environment(x)

Usage

chk_environment(x, x_name = NULL)vld_environment(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.environment()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_double(),chk_integer(),chk_logical(),chk_numeric(),chk_raw()

Examples

# chk_environmentchk_environment(.GlobalEnv)try(chk_environment(1))# vld_environmentvld_environment(1)vld_environment(list(1))vld_environment(.GlobalEnv)vld_environment(environment())

Check Equal

Description

Checks if is equal (identical within tolerance) to y using

vld_true(all.equal(x, y, tolerance))

Usage

chk_equal(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL)vld_equal(x, y, tolerance = sqrt(.Machine$double.eps))

Arguments

x

The object to check.

y

An object to check against.

tolerance

A non-negative numeric scalar.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_true()

all.equal()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equal(),chk_all_equivalent(),chk_all_identical(),chk_equivalent(),chk_identical()

Examples

# chk_equalchk_equal(1, 1.00000001)try(chk_equal(1, 1.0000001))chk_equal(1, 1L)chk_equal(c(x = 1), c(x = 1L))try(chk_equal(c(x = 1), c(y = 1L)))vld_equal(1, 1.00000001)

Check Equivalent

Description

Checks if is equivalent (equal ignoring attributes) to y using

vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))

Usage

chk_equivalent(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL)vld_equivalent(x, y, tolerance = sqrt(.Machine$double.eps))

Arguments

x

The object to check.

y

An object to check against.

tolerance

A non-negative numeric scalar.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_true()

all.equal()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equal(),chk_all_equivalent(),chk_all_identical(),chk_equal(),chk_identical()

Examples

# chk_equivalentchk_equivalent(1, 1.00000001)try(chk_equivalent(1, 1.0000001))chk_equivalent(1, 1L)chk_equivalent(c(x = 1), c(y = 1))vld_equivalent(c(x = 1), c(y = 1L))

Check File Extension

Description

Checks extension using

vld_string(x) && vld_subset(tools::file_ext(x), ext)

The user may want to usetoupper() ortolower()to ensure the case matches.

Usage

chk_ext(x, ext, x_name = NULL)vld_ext(x, ext)

Arguments

x

The object to check.

ext

A character vector of the permitted file extensions(without the .).

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_string()

vld_subset()

For more details about the use of this function,please read the articlevignette("chk-families").

Other file_checkers:chk_dir(),chk_file()

Examples

# chk_exttry(chk_ext("file1.pdf", "png"))# vld_extvld_ext("oeu.pdf", "pdf")vld_ext(toupper("oeu.pdf"), "PDF")

Check Factor

Description

Checks if factor using

is.factor(x)

Usage

chk_factor(x, x_name = NULL)vld_factor(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.factor()

For more details about the use of this function,please read the articlevignette("chk-families").

Other factor_checkers:chk_character_or_factor()

Examples

# chk_factorchk_factor(factor("1"))try(chk_factor("1"))# vld_factorvld_factor(factor("1"))vld_factor(factor(0))vld_factor("1")vld_factor(1L)

Check FALSE

Description

Check if FALSE using

is.logical(x) && length(x) == 1L && !anyNA(x) && !x

Usage

chk_false(x, x_name = NULL)vld_false(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.logical()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other logical_checkers:chk_flag(),chk_lgl(),chk_logical(),chk_true()

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Examples

# chk_falsechk_false(FALSE)try(chk_false(0))# vld_falsevld_false(TRUE)vld_false(FALSE)vld_false(NA)vld_false(0)vld_false(c(FALSE, FALSE))

Check File Exists

Description

Checks if file exists using

vld_string(x) && file.exists(x) && !dir.exists(x)

Usage

chk_file(x, x_name = NULL)vld_file(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

vld_string()

file.exists()

dir.exists()

For more details about the use of this function,please read the articlevignette("chk-families").

Other file_checkers:chk_dir(),chk_ext()

Examples

# chk_filetry(chk_file(tempfile()))# vld_filevld_file(tempfile())

Check Flag

Description

Checks if non-missing logical scalar using

is.logical(x) && length(x) == 1L && !anyNA(x)

Pass:TRUE,FALSE.

Fail:logical(0),c(TRUE, TRUE),"TRUE",1,NA.

Do not confuse this function withchk_lgl(),which also checks for logical scalars oflength(x) == 1but can includeNAs.

Usage

chk_flag(x, x_name = NULL)vld_flag(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.logical()length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other logical_checkers:chk_false(),chk_lgl(),chk_logical(),chk_true()

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_lgl(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Examples

# chk_flagchk_flag(TRUE)try(vld_flag(1))# vld_flagvld_flag(TRUE)vld_flag(1)

Check Function

Description

Checks if is a function using

is.function(x) && (is.null(formals) || length(formals(x)) == formals)

Usage

chk_function(x, formals = NULL, x_name = NULL)vld_function(x, formals = NULL)

Arguments

x

The object to check.

formals

A count of the number of formal arguments.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.function()formals()

For more details about the use of this function,please read the articlevignette("chk-families").

Other missing_checkers:chk_missing(),chk_not_missing()

Examples

# chk_functionchk_function(mean)try(chk_function(1))# vld_functionvld_function(mean)vld_function(function(x) x)vld_function(1)vld_function(list(1))

Check Greater Than

Description

Checks if all non-missing values are greater than value using

all(x[!is.na(x)] > value)

Usage

chk_gt(x, value = 0, x_name = NULL)vld_gt(x, value = 0)

Arguments

x

The object to check.

value

A non-missing scalar of a value.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other range_checkers:chk_gte(),chk_lt(),chk_lte(),chk_range()

Examples

# chk_gtchk_gt(0.1)try(chk_gt(c(0.1, -0.2)))# vld_gtvld_gt(numeric(0))vld_gt(0)vld_gt(0.1)vld_gt(c(0.1, 0.2, NA))vld_gt(c(0.1, -0.2))vld_gt(c(-0.1, 0.2), value = -1)vld_gt("b", value = "a")

Check Greater Than or Equal To

Description

Checks if all non-missing values are greater than or equal to y using

all(x[!is.na(x)] >= value)

Usage

chk_gte(x, value = 0, x_name = NULL)vld_gte(x, value = 0)

Arguments

x

The object to check.

value

A non-missing scalar of a value.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other range_checkers:chk_gt(),chk_lt(),chk_lte(),chk_range()

Examples

# chk_gtechk_gte(0)try(chk_gte(-0.1))# vld_gtevld_gte(numeric(0))vld_gte(0)vld_gte(-0.1)vld_gte(c(0.1, 0.2, NA))vld_gte(c(0.1, 0.2, NA), value = 1)

Check Identical

Description

Checks if is identical to y using

identical(x, y)

Usage

chk_identical(x, y, x_name = NULL)vld_identical(x, y)

Arguments

x

The object to check.

y

An object to check against.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

identical()

For more details about the use of this function,please read the articlevignette("chk-families").

Other equal_checkers:chk_all_equal(),chk_all_equivalent(),chk_all_identical(),chk_equal(),chk_equivalent()

Examples

# chk_identicalchk_identical(1, 1)try(chk_identical(1, 1L))chk_identical(c(1, 1), c(1, 1))try(chk_identical(1, c(1, 1)))vld_identical(1, 1)

Check Integer

Description

Checks if integer using

is.integer(x)

Usage

chk_integer(x, x_name = NULL)vld_integer(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.integer()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_double(),chk_environment(),chk_logical(),chk_numeric(),chk_raw()

Examples

# chk_integerchk_integer(1L)try(chk_integer(1))# vld_integervld_integer(1L)vld_integer(matrix(1:4, nrow = 2L))vld_integer(integer(0))vld_integer(NA_integer_)vld_integer(1)vld_integer(TRUE)

Check Class

Description

Checks inherits from class using

inherits(x, class)

Usage

chk_is(x, class, x_name = NULL)vld_is(x, class)

Arguments

x

The object to check.

class

A string specifying the class.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

inherits()

For more details about the use of this function,please read the articlevignette("chk-families").

Other id_checkers:chk_data(),chk_s3_class(),chk_s4_class()

Examples

chk_is(1, "numeric")try(chk_is(1L, "double"))# vld_isvld_is(numeric(0), "numeric")vld_is(1L, "double")

Check Join

Description

Checks if all rows in x match at least one in y.

Usage

chk_join(x, y, by, x_name = NULL)vld_join(x, y, by)

Arguments

x

The object to check.

y

A data.frame with columns in by.

by

A character vector specifying the column names to join x and y on.If named the names are the corresponding columns in x.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

For more details about the use of this function,please read the articlevignette("chk-families").

Other misc_checkers:chk_not_any_na(),chk_not_empty(),chk_unique()

Examples

# chk_joinchk_join(data.frame(z = 1), data.frame(z = 1:2), by = "z")try(chk_join(data.frame(z = 1), data.frame(z = 2), by = "z"))# vld_joinvld_join(data.frame(z = 1), data.frame(z = 1:2), by = "z")vld_join(data.frame(z = 1), data.frame(z = 2), by = "z")vld_join(data.frame(z = 1), data.frame(a = 1:2), by = c(z = "a"))vld_join(data.frame(z = 1), data.frame(a = 2), by = c(z = "a"))

Check Length

Description

Checks length is a particular value or range using

length(x) >= length && length(x) <= upper

Usage

chk_length(x, length = 1L, upper = length, x_name = NULL)vld_length(x, length = 1L, upper = length)

Arguments

x

The object to check.

length

A count of the length.

upper

A count of the max length.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length(),check_length(),check_dim()

For more details about the use of this function,please read the articlevignette("chk-families").

Other length_checkers:chk_compatible_lengths()

Examples

# chk_lengthchk_length("text")try(vld_length("text", length = 2))# vld_lengthvld_length(2:1, 2)vld_length(2:1, 1)

Check Logical Scalar

Description

Checks if logical scalar using

is.logical(x) && length(x) == 1L

If you only want to check the data type (not whetherlength(x) == 1),you should use thechk_logical() function.

Usage

chk_lgl(x, x_name = NULL)vld_lgl(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.logical()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other logical_checkers:chk_false(),chk_flag(),chk_logical(),chk_true()

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_scalar(),chk_string(),chk_true(),chk_tz()

Examples

# chk_lglchk_lgl(NA)try(chk_lgl(1))# vld_lglvld_lgl(TRUE)vld_lgl(FALSE)vld_lgl(NA)vld_lgl(1)vld_lgl(c(TRUE, TRUE))

Check List

Description

Checks if is a list using

is.list(x)

Usage

chk_list(x, x_name = NULL)vld_list(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.list()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_structure_checkers:chk_array(),chk_atomic(),chk_matrix(),chk_vector()

Examples

# chk_listchk_list(list())try(chk_list(1))# vld_listvld_list(list())vld_list(list(x = 1))vld_list(mtcars)vld_list(1)vld_list(NULL)

Check Logical

Description

Checks if logical using

is.logical(x)

If you want to check if it is a scalar,meaning that in addition to being of logical type,it haslength(x) == 1, you should usechk_lgl()

Usage

chk_logical(x, x_name = NULL)vld_logical(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.logical()

For more details about the use of this function,please read the articlevignette("chk-families").

Other logical_checkers:chk_false(),chk_flag(),chk_lgl(),chk_true()

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_double(),chk_environment(),chk_integer(),chk_numeric(),chk_raw()

Examples

# chk_logicalchk_logical(TRUE)try(chk_logical(1))# vld_logicalvld_logical(TRUE)vld_logical(matrix(TRUE))vld_logical(logical(0))vld_logical(NA)vld_logical(1)vld_logical("TRUE")

Check Less Than

Description

Checks if all non-missing values are less than value using

all(x[!is.na(x)] < value)

Usage

chk_lt(x, value = 0, x_name = NULL)vld_lt(x, value = 0)

Arguments

x

The object to check.

value

A non-missing scalar of a value.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other range_checkers:chk_gt(),chk_gte(),chk_lte(),chk_range()

Examples

# chk_ltchk_lt(-0.1)try(chk_lt(c(-0.1, 0.2)))# vld_ltvld_lt(numeric(0))vld_lt(0)vld_lt(-0.1)vld_lt(c(-0.1, -0.2, NA))vld_lt(c(-0.1, 0.2))vld_lt(c(-0.1, 0.2), value = 1)vld_lt("a", value = "b")

Check Less Than or Equal To

Description

Checks if all non-missing values are less than or equal to y using

all(x[!is.na(x)] <= value)

Usage

chk_lte(x, value = 0, x_name = NULL)vld_lte(x, value = 0)

Arguments

x

The object to check.

value

A non-missing scalar of a value.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other range_checkers:chk_gt(),chk_gte(),chk_lt(),chk_range()

Examples

# chk_ltechk_lte(0)try(chk_lte(0.1))# vld_ltevld_lte(numeric(0))vld_lte(0)vld_lte(0.1)vld_lte(c(-0.1, -0.2, NA))vld_lte(c(-0.1, -0.2, NA), value = -1)

Check Matches

Description

Checks if all values match regular expression using

all(grepl(regexp, x[!is.na(x)]))

Usage

chk_match(x, regexp = ".+", x_name = NULL)vld_match(x, regexp = ".+")

Arguments

x

The object to check.

regexp

A string of a regular expression.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

grepl()

For more details about the use of this function,please read the articlevignette("chk-families").

Examples

# chk_matchchk_match("1")try(chk_match("1", regexp = "2"))# vld_matchvld_match("1")vld_match("a", regexp = "a")vld_match("")vld_match("1", regexp = "2")vld_match(NA_character_, regexp = ".*")

Check Matrix

Description

Checks if is a matrix using

is.matrix(x)

Usage

chk_matrix(x, x_name = NULL)vld_matrix(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.matrix()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_structure_checkers:chk_array(),chk_atomic(),chk_list(),chk_vector()

Examples

# chk_matrixchk_matrix(matrix(1))try(chk_matrix(array(1)))# vld_matrixvld_matrix(1)vld_matrix(matrix(1))

Check Missing Argument

Description

Checks argument missing using

missing(x)

Usage

chk_missing(x, x_name = NULL)vld_missing(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Details

Currently only checks if value is available(as opposed to whether it was specified).

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

missing()

For more details about the use of this function,please read the articlevignette("chk-families").

Other missing_checkers:chk_function(),chk_not_missing()

Examples

# chk_missingfun <- function(x) {  chk_missing(x)}fun()try(fun(1))# vld_missingfun <- function(x) {  vld_missing(x)}fun()fun(1)

Check Named

Description

Checks if is named using

!is.null(names(x))

Usage

chk_named(x, x_name = NULL)vld_named(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

names()

is.null()

For more details about the use of this function,please read the articlevignette("chk-families").

Other name_checkers:chk_valid_name()

Examples

# chk_namedchk_named(c(x = 1))try(chk_named(list(1)))# vld_namedvld_named(c(x = 1))vld_named(list(x = 1))vld_named(c(x = 1)[-1])vld_named(list(x = 1)[-1])vld_named(1)vld_named(list(1))

Check Not Any Missing Values

Description

Checks if not any missing values using

!anyNA(x)

Pass:1,1:2,"1",logical(0).

Fail:NA,c(1, NA).

Usage

chk_not_any_na(x, x_name = NULL)vld_not_any_na(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

For more details about the use of this function,please read the articlevignette("chk-families").

Other misc_checkers:chk_join(),chk_not_empty(),chk_unique()

Examples

# chk_not_any_nachk_not_any_na(1)try(chk_not_any_na(NA))# vld_not_any_navld_not_any_na(1)vld_not_any_na(1:2)vld_not_any_na(NA_real_)vld_not_any_na(integer(0))vld_not_any_na(c(NA, 1))vld_not_any_na(TRUE)

Check Not Empty

Description

Checks if not empty using

length(x) != 0L

Pass:1,1:2,NA,matrix(1:3),list(1),data.frame(x = 1).

Fail:NULL,logical(0),list(),data.frame().

Usage

chk_not_empty(x, x_name = NULL)vld_not_empty(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other misc_checkers:chk_join(),chk_not_any_na(),chk_unique()

Examples

# chk_not_emptychk_not_empty(1)try(chk_not_empty(numeric(0)))# vld_not_emptyvld_not_empty(1)vld_not_empty(matrix(1:3))vld_not_empty(character(0))vld_not_empty(list(1))vld_not_empty(NULL)vld_not_empty(list())

Check Not Missing Argument

Description

Checks argument not missing using

!missing(x)

Usage

chk_not_missing(x, x_name = "`x`")vld_not_missing(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Details

Currently only checks if value is available(as opposed to whether it was specified).

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

missing()

For more details about the use of this function,please read the articlevignette("chk-families").

Other missing_checkers:chk_function(),chk_missing()

Examples

# chk_not_missingfun <- function(x) {  chk_not_missing(x)}fun(1)try(fun())# vld_not_missingfun <- function(x) {  vld_not_missing(x)}fun()fun(1)

Check not NULL

Description

Checks if not NULL using

!is.null(x)

Usage

chk_not_null(x, x_name = NULL)vld_not_null(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.null()

For more details about the use of this function,please read the articlevignette("chk-families").

Other null_checkers:chk_null()

Examples

# chk_not_nulltry(chk_not_null(NULL))chk_not_null(1)# vld_not_nullvld_not_null(1)vld_not_null(NULL)

Check Not Subset

Description

Checks if not all values in values using

!any(x %in% values) || !length(x)

Usage

chk_not_subset(x, values, x_name = NULL)

Arguments

x

The object to check.

values

A vector of the permitted values.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

See Also

any()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other set_checkers:chk_orderset(),chk_superset(),vld_not_subset(),vld_orderset()

Examples

# chk_not_subsetchk_not_subset(11, 1:10)try(chk_not_subset(1, 1:10))

Check NULL

Description

Checks if NULL using

is.null(x)

Usage

chk_null(x, x_name = NULL)vld_null(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.null()

For more details about the use of this function,please read the articlevignette("chk-families").

Other null_checkers:chk_not_null()

Examples

# chk_nulltry(chk_null(1))chk_null(NULL)# vld_nullvld_null(NULL)vld_null(1)

Check NULL Or

Description

Checks if NULL or passes test.

Usage

chk_null_or(x, chk, ..., vld, x_name = NULL)

Arguments

x

The object to check.

chk

A chk function. Soft-deprecated for vld.[Deprecated]

...

Arguments passed to chk.

vld

A vld function.

x_name

A string of the name of object x or NULL.

Value

An informative error if the test fails.

Examples

chk_null_or(NULL, chk_number)chk_null_or(1, chk_number)try(chk_null_or("1", chk_number))

Check Number

Description

Checks if non-missing numeric scalar using

is.numeric(x) && length(x) == 1L && !anyNA(x)

Pass:1,2L,log(10),-Inf

Fail:"a",1:3,NA_real_

Usage

chk_number(x, x_name = NULL)vld_number(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.numeric()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Examples

# chk_numberchk_number(1.1)try(chk_number(TRUE))# vld_numbervld_number(1.1)

Check Numeric

Description

Checks if numeric using

is.numeric(x)

Pass:1,1:2,NA_real_,integer(0),matrix(1:3).

Fail:TRUE,"1",NA,NULL.

Usage

chk_numeric(x, x_name = NULL)vld_numeric(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.numeric()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_double(),chk_environment(),chk_integer(),chk_logical(),chk_raw()

Examples

# chk_numericchk_numeric(1)try(chk_numeric("1"))# vld_numericvld_numeric(1)vld_numeric(1:2)vld_numeric(NA_real_)vld_numeric(integer(0))vld_numeric("1")vld_numeric(TRUE)

Check Set Ordered

Description

Checks if the first occurrence of each shared elementin x is equivalent to the first occurrence of each shared element in values usingvld_equivalent(unique(x[x %in% values]), values[values %in% x]).

Usage

chk_orderset(x, values, x_name = NULL)

Arguments

x

The object to check.

values

A vector of the permitted values.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails.

Thevld_ function returns a flag indicating whether the test was met.

See Also

vld_equivalent()

unique()

For more details about the use of this function,please read the articlevignette("chk-families").

Other set_checkers:chk_not_subset(),chk_superset(),vld_not_subset(),vld_orderset()

Examples

# chk_ordersetchk_orderset(1:2, 1:2)try(chk_orderset(2:1, 1:2))

Checks range of non-missing values

Description

Checks all non-missing values fall within range using

If inclusive

all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])

else

all(x[!is.na(x)] > range[1] & x[!is.na(x)] < range[2])

Usage

chk_range(x, range = c(0, 1), inclusive = TRUE, x_name = NULL)vld_range(x, range = c(0, 1), inclusive = TRUE)

Arguments

x

The object to check.

range

A non-missing sorted vector of length 2 of the lower andupper permitted values.

inclusive

A flag specifying whether the range is exclusive.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other range_checkers:chk_gt(),chk_gte(),chk_lt(),chk_lte()

Examples

# chk_rangechk_range(0)try(chk_range(-0.1))# vld_rangevld_range(numeric(0))vld_range(0)vld_range(-0.1)vld_range(c(0.1, 0.2, NA))vld_range(c(0.1, 0.2, NA), range = c(0, 1))

Check Raw

Description

Checks if raw using

is.raw(x)

Usage

chk_raw(x, x_name = NULL)vld_raw(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.raw()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_type_checkers:chk_character(),chk_character_or_factor(),chk_complex(),chk_double(),chk_environment(),chk_integer(),chk_logical(),chk_numeric()

Examples

# chk_rawchk_raw(as.raw(1))try(chk_raw(1))# vld_rawvld_raw(as.raw(1))vld_raw(raw(0))vld_raw(1)vld_raw(TRUE)

Check Type

Description

Checks inherits from S3 class using

!isS4(x) && inherits(x, class)

Usage

chk_s3_class(x, class, x_name = NULL)vld_s3_class(x, class)

Arguments

x

The object to check.

class

A string specifying the class.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

inherits()

For more details about the use of this function,please read the articlevignette("chk-families").

Other id_checkers:chk_data(),chk_is(),chk_s4_class()

Examples

# chk_s3_classchk_s3_class(1, "numeric")try(chk_s3_class(getClass("MethodDefinition"), "classRepresentation"))# vld_s3_classvld_s3_class(numeric(0), "numeric")vld_s3_class(getClass("MethodDefinition"), "classRepresentation")

Check Inherits from S4 Class

Description

Checks inherits from S4 class using

isS4(x) && methods::is(x, class)

Usage

chk_s4_class(x, class, x_name = NULL)vld_s4_class(x, class)

Arguments

x

The object to check.

class

A string specifying the class.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

methods::is()

For more details about the use of this function,please read the articlevignette("chk-families").

Other id_checkers:chk_data(),chk_is(),chk_s3_class()

Examples

# chk_s4_classtry(chk_s4_class(1, "numeric"))chk_s4_class(getClass("MethodDefinition"), "classRepresentation")# vld_s4_classvld_s4_class(numeric(0), "numeric")vld_s4_class(getClass("MethodDefinition"), "classRepresentation")

Check Scalar

Description

Checks if is a vector using

length(x) == 1L

Usage

chk_scalar(x, x_name = NULL)vld_scalar(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_string(),chk_true(),chk_tz()

Examples

# chk_scalarchk_scalar(1)chk_scalar(list(1))try(chk_scalar(1:2))# vld_scalarvld_scalar(1)

Check Sorted

Description

Checks if is sorted using

is.unsorted(x, na.rm = TRUE)

Usage

chk_sorted(x, x_name = NULL)vld_sorted(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.unsorted()

For more details about the use of this function,please read the articlevignette("chk-families").

Examples

# chk_sortedchk_sorted(1:2)try(chk_sorted(2:1))# vld_sortedvld_sorted(1:2)vld_sorted(2:1)

Check String

Description

Checks if string

is.character(x) && length(x) == 1L && !anyNA(x)

Usage

chk_string(x, x_name = NULL)vld_string(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_true(),chk_tz()

Examples

# chk_stringchk_string("1")try(chk_string(1))# vld_stringvld_string("1")vld_string("")vld_string(1)vld_string(NA_character_)vld_string(c("1", "1"))

Check Superset

Description

Checks if includes all values using

all(values %in% x)

Pay attention to the order of the argumentsvalue andxin this function compared tochk_subset()

Usage

chk_superset(x, values, x_name = NULL)vld_superset(x, values)

Arguments

x

The object to check.

values

A vector of the permitted values.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other set_checkers:chk_not_subset(),chk_orderset(),vld_not_subset(),vld_orderset()

Examples

# chk_supersetchk_superset(1:3, 1)try(chk_superset(1:3, 4))# vld_supersetvld_superset(1:3, 1)vld_superset(1:3, 4)vld_superset(integer(0), integer(0))

Check TRUE

Description

Checks if TRUE using

is.logical(x) && length(x) == 1L && !anyNA(x) && x

Usage

chk_true(x, x_name = NULL)vld_true(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.logical()

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other logical_checkers:chk_false(),chk_flag(),chk_lgl(),chk_logical()

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_tz()

Examples

# chk_truechk_true(TRUE)try(chk_true(1))# vld_truevld_true(TRUE)vld_true(FALSE)vld_true(NA)vld_true(0)vld_true(c(TRUE, TRUE))

Check Time Zone

Description

Checks if non-missing valid scalar timezone using

is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames()

Usage

chk_tz(x, x_name = NULL)vld_tz(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

length()

OlsonNames()

is.character()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checkers:chk_count(),chk_date(),chk_date_time(),chk_false(),chk_flag(),chk_lgl(),chk_scalar(),chk_string(),chk_true()

Examples

chk_tz("UTC")try(chk_tz("TCU"))vld_tz("UTC")vld_tz("TCU")

Check Unique

Description

Checks if unique using

!anyDuplicated(x, incomparables = incomparables)

Usage

chk_unique(x, incomparables = FALSE, x_name = NULL)vld_unique(x, incomparables = FALSE)

Arguments

x

The object to check.

incomparables

A vector of values that cannot be compared.FALSE means that all values can be compared.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

anyDuplicated()

For more details about the use of this function,please read the articlevignette("chk-families").

Other misc_checkers:chk_join(),chk_not_any_na(),chk_not_empty()

Examples

# chk_uniquechk_unique(c(NA, 2))try(chk_unique(c(NA, NA, 2)))chk_unique(c(NA, NA, 2), incomparables = NA)# vld_uniquevld_unique(NULL)vld_unique(numeric(0))vld_unique(c(NA, 2))vld_unique(c(NA, NA, 2))vld_unique(c(NA, NA, 2), incomparables = NA)

Check ... Unused

Description

Checks if ... is unused

length(list(...)) == 0L

Usage

chk_unused(...)vld_unused(...)

Arguments

...

Additional arguments.

Value

Thechk_ function throws an informative error if the test fails.

Functions

See Also

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other ellipsis_checkers:chk_used()

Examples

# chk_unusedfun <- function(x, ...) {  chk_unused(...)  x}fun(1)try(fun(1, 2))# vld_unusedfun <- function(x, ...) {  vld_unused(...)}fun(1)try(fun(1, 2))

Check ... Used

Description

Checks if is ... used using

length(list(...)) != 0L

Usage

chk_used(...)vld_used(...)

Arguments

...

Additional arguments.

Value

Thechk_ function throws an informative error if the test fails.

Functions

See Also

length()

For more details about the use of this function,please read the articlevignette("chk-families").

Other ellipsis_checkers:chk_unused()

Examples

# chk_usedfun <- function(x, ...) {  chk_used(...)  x}try(fun(1))fun(1, 2)# vld_usedfun <- function(x, ...) {  vld_used(...)}fun(1)fun(1, 2)

Check Valid Name

Description

Checks if valid name using

identical(make.names(x[!is.na(x)]), as.character(x[!is.na(x)]))

Usage

chk_valid_name(x, x_name = NULL)vld_valid_name(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

identical()

make.names()

For more details about the use of this function,please read the articlevignette("chk-families").

Other name_checkers:chk_named()

Examples

# chk_valid_namechk_valid_name("text")try(chk_valid_name(".1"))# vld_valid_namevld_valid_name(".1")

Check Vector

Description

Checks if is a vector using

(is.atomic(x) && !is.matrix(x) && !is.array(x)) || is.list(x)

Usage

chk_vector(x, x_name = NULL)vld_vector(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Details

is.vector(x) is not reliable because it returns TRUE onlyif the object is a vector with no attributes apart from names.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.atomic(),is.matrix(),is.array(),is.list()

For more details about the use of this function,please read the articlevignette("chk-families").

Other data_structure_checkers:chk_array(),chk_atomic(),chk_list(),chk_matrix()

Examples

# chk_vectorchk_vector(1)chk_vector(list())try(chk_vector(matrix(1)))# vld_vectorvld_vector(1)

Check Whole Number

Description

Checks if non-missing integer scalar or double equivalent using

vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))

Pass:1,2L,1e10,-Inf

Fail:"a",1:3,NA_integer_,log(10)

Usage

chk_whole_number(x, x_name = NULL)vld_whole_number(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.integer()

vld_true()

vld_number()

For more details about the use of this function,please read the articlevignette("chk-families").

Other scalar_checker:chk_complex_number()

Other whole_number_checkers:chk_count(),chk_whole_numeric()

Examples

# chk_whole_numberchk_whole_number(2)try(chk_whole_number(1.1))# vld_whole_numbervld_whole_number(2)

Check Whole Numeric

Description

Checks if integer vector or double equivalent using

is.integer(x) || (is.double(x) && vld_true(all.equal(x, as.integer(x))))

Usage

chk_whole_numeric(x, x_name = NULL)vld_whole_numeric(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

is.integer()

is.double()

vld_true()

all.equal()

For more details about the use of this function,please read the articlevignette("chk-families").

Other whole_number_checkers:chk_count(),chk_whole_number()

Examples

# chk_whole_numericchk_whole_numeric(1)try(chk_whole_numeric(1.1))# vld_whole_numericvld_whole_numeric(1)vld_whole_numeric(NA_real_)vld_whole_numeric(1:2)vld_whole_numeric(double(0))vld_whole_numeric(TRUE)vld_whole_numeric(1.5)

Check Whole Numeric Scalar

Description

Checks if whole numeric scalar using

is.numeric(x) && length(x) == 1L && (is.integer(x) || vld_true(all.equal(x, trunc(x))))

[Deprecated]

Usage

chk_wnum(x, x_name = NULL)vld_wnum(x)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

Other deprecated:chk_chr(),chk_dbl(),chk_deprecated

Examples

# chk_wnumchk_wnum(1)try(chk_wnum(1.1))# vld_wnumvld_wnum(1)vld_wnum(double(0))vld_wnum(NA_real_)vld_wnum(c(1, 1))vld_wnum(1L)

Check OR

Description

Thechkor() function has been deprecated for the fasterchkor_vld().

Usage

chkor(...)

Arguments

...

Multiplechk_ functions.

Details

[Deprecated]

Value

An informative error if the test fails.

See Also

chk_null_or()

Examples

chkor()chkor(chk_flag(TRUE))try(chkor(chk_flag(1)))try(chkor(chk_flag(1), chk_flag(2)))chkor(chk_flag(1), chk_flag(TRUE))

Chk OR

Description

Chk OR

Usage

chkor_vld(...)

Arguments

...

Multiplevld_ calls.

A common mistake is to passchk_ calls.

chkor_vld() is relatively slow.If at all possible usechk_null_or() or first test using the individualvld_ functions and then callchkor_vld() to generate an informativeerror message.

Value

An informative error if the test fails.

See Also

chk_null_or()

Examples

chkor_vld()chkor_vld(vld_flag(TRUE))try(chkor_vld(vld_flag(1)))try(chkor_vld(vld_flag(1), vld_flag(2)))chkor_vld(vld_flag(1), vld_flag(TRUE))

Deparse Backtick

Description

deparse_backtick_chk is a wrapper ondeparse()andbacktick_chk.

Usage

deparse_backtick_chk(x)backtick_chk(x)unbacktick_chk(x)

Arguments

x

A substituted object to deparse.

Details

It is exported to allow users to easily construct their ownchk_ functions.

Value

A string of the backticked substituted object.

Functions

See Also

deparse()

Examples

# deparse_backtick_chkdeparse_backtick_chk(2)deparse_backtick_chk(2^2)

Stop, Warning and Message Messages

Description

The functions callmessage_chk() to processthe message and thenrlang::abort(),rlang::warn() andrlang::inform(), respectively.

Usage

err(  ...,  n = NULL,  tidy = TRUE,  .subclass = NULL,  class = NULL,  call = rlang::caller_call(3))wrn(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL)msg(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL)

Arguments

...

zero or more objects which can be coerced to character(and which are pasted together with no separator) or a singlecondition object.

n

The value of n for convertingsprintf-like types.

tidy

A flag specifying whether capitalize the first character and add a missing period.

.subclass

A string of the class of the error message.

class

Subclass of the condition.

call

The execution environment of a currently runningfunction, e.g.call = caller_env(). The corresponding functioncall is retrieved and mentioned in error messages as the sourceof the error.

You only need to supplycall when throwing a condition from ahelper function which wouldn't be relevant to mention in themessage.

Can also beNULL or adefused function call torespectively not display any call or hard-code a code to display.

For more information about error calls, seeIncluding function calls in error messages.

Details

The user can set the subclass.

Functions

Examples

# errtry(err("there %r %n problem value%s", n = 2))# wrnwrn("there %r %n problem value%s", n = 2)# msgmsg("there %r %n problem value%s", n = 2)

Expect Chk Error

Description

expect_chk_error() checks that code throws an errorof class"chk_error" with a message that matches regexp.See below for more details.

Usage

expect_chk_error(  object,  regexp = NULL,  ...,  info = NULL,  label = NULL,  class = NULL)

Arguments

object

Object to test.

Supports limited unquoting to make it easier to generate readable failureswithin a function or for loop. Seequasi_label for more details.

regexp

Regular expression to test against.

  • A character vector giving a regular expression that must match theerror message.

  • IfNULL, the default, asserts that there should be an error,but doesn't test for a specific value.

  • IfNA, asserts that there should be no errors, but we now recommendusingexpect_no_error() and friends instead.

Note that you should only usemessage with errors/warnings/messagesthat you generate. Avoid tests that rely on the specific text generated byanother package since this can easily change. If you do need to test textgenerated by another package, either protect the test withskip_on_cran()or useexpect_snapshot().

...

Arguments passed on toexpect_match

fixed

IfTRUE, treatsregexp as a string to be matched exactly(not a regular expressions). Overridesperl.

perl

logical. Should Perl-compatible regexps be used?

info

Extra information to be included in the message. This argumentis soft-deprecated and should not be used in new code. Instead seealternatives inquasi_label.

label

Used to customise failure messages. For expert use only.

class

Must be NULL.

Value

Ifregexp = NA, the value of the first argument; otherwisethe captured condition.

Testingmessage vsclass

When checking that code generates an error, it's important to check that theerror is the one you expect. There are two ways to do this. The firstway is the simplest: you just provide aregexp that match some fragmentof the error message. This is easy, but fragile, because the test willfail if the error message changes (even if its the same error).

A more robust way is to test for the class of the error, if it has one.You can learn more about custom conditions athttps://adv-r.hadley.nz/conditions.html#custom-conditions, but inshort, errors are S3 classes and you can generate a custom class and checkfor it usingclass instead ofregexp.

If you are usingexpect_error() to check that an error message isformatted in such a way that it makes sense to a human, we recommendusingexpect_snapshot() instead.

See Also

expect_no_error(),expect_no_warning(),expect_no_message(), andexpect_no_condition() to assertthat code runs without errors/warnings/messages/conditions.

Other expectations:comparison-expectations,equality-expectations,expect_length(),expect_match(),expect_named(),expect_null(),expect_output(),expect_reference(),expect_silent(),inheritance-expectations,logical-expectations

Examples

expect_chk_error(chk_true(FALSE))try(expect_chk_error(chk_false(FALSE)))

Construct Tidyverse Style Message

Description

Iftidy = TRUE constructs a tidyverse style message by

Usage

message_chk(..., n = NULL, tidy = TRUE)

Arguments

...

Multiple objects that are converted to a string usingpaste0(..., collapse = '').

n

The value of n for convertingsprintf-like types.

tidy

A flag specifying whether capitalize the first character and add a missing period.

Details

Also ifn != NULL replaces the recognizedsprintf-like types.

Value

A string of the message.

sprintf-like types

The following recognizedsprintf-like types can be used in a message:

n

The value of n.

s

” if n == 1 otherwise 's'

r

'is' if n == 1 otherwise 'are'

y

'y' if n == 1 otherwise 'ie'

Examples

message_chk("there %r %n", " problem director%y%s")message_chk("there %r %n", " problem director%y%s", n = 1)message_chk("There %r %n", " problem director%y%s.", n = 3)

Concatenate Strings

Description

A wrapper onbase::paste().

Usage

p(..., sep = " ", collapse = NULL)p0(..., collapse = NULL)

Arguments

...

one or moreR objects, to be converted to character vectors.

sep

a character string to separate the terms. NotNA_character_.

collapse

an optional character string to separate the results. NotNA_character_. Whencollapse is a string,the result is always a string (character of length 1).

Value

A character vector.

Functions

Examples

p("a", "b")p(c("a", "b"), collapse = " ")p0("a", "b")p0(c("a", "b"), collapse = "")

Parameter Descriptions for chk Package

Description

Default parameter descriptions which may be overridden in individualfunctions.

Arguments

...

Additional arguments.

x

The object to check.

x_name

A string of the name of object x or NULL.

y

An object to check against.

chk

A flag specifying whether to check the other parameters.

chk_fun

A chk_ function.

tolerance

A non-negative numeric scalar.

ext

A character vector of the permitted file extensions(without the .).

exists

A flag specifying whether the files/directories must (or must not) exist.

value

A non-missing scalar of a value.

range

A non-missing sorted vector of length 2 of the lower andupper permitted values.

inclusive

A flag specifying whether the range is exclusive.

regexp

A string of a regular expression.

values

A vector of the permitted values.

class

A string specifying the class.

length

A count of the length.

upper

A count of the max length.

formals

A count of the number of formal arguments.

incomparables

A vector of values that cannot be compared.FALSE means that all values can be compared.

by

A character vector specifying the column names to join x and y on.If named the names are the corresponding columns in x.

exclusive

A flag specifying whether x must only include columns named in values.

order

A flag specifying whether the order of columns in x must match names in values.

nrow

A flag or a whole numeric vector of the value, value range or possible values.

key

A character vector of the columns that represent a unique key.

vld_fun

A vld_ function.

Details

A flag is a non-missing logical scalar.

A string is a non-missing character scalar.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.


Check Subset

Description

Checks if all values in values using

all(x %in% values)

Pay attention to the order of the argumentsvalue andxin this function compared tochk_superset()

Usage

vld_not_subset(x, values)chk_subset(x, values, x_name = NULL)vld_subset(x, values)

Arguments

x

The object to check.

values

A vector of the permitted values.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

all()

For more details about the use of this function,please read the articlevignette("chk-families").

Other set_checkers:chk_not_subset(),chk_orderset(),chk_superset(),vld_orderset()

Examples

# vld_not_subsetvld_not_subset(numeric(0), 1:10)vld_not_subset(1, 1:10)vld_not_subset(11, 1:10)# chk_subsetchk_subset(1, 1:10)try(chk_subset(11, 1:10))# vld_subsetvld_subset(numeric(0), 1:10)vld_subset(1, 1:10)vld_subset(11, 1:10)

Check Set Equal

Description

Checks if equal set using

setequal(x, values)

Usage

vld_orderset(x, values)chk_setequal(x, values, x_name = NULL)vld_setequal(x, values)

Arguments

x

The object to check.

values

A vector of the permitted values.

x_name

A string of the name of object x or NULL.

Value

Thechk_ function throws an informative error if the test fails orreturns the original object if successful so it can used in pipes.

Thevld_ function returns a flag indicating whether the test was met.

Functions

See Also

setequal()

For more details about the use of this function,please read the articlevignette("chk-families").

Other set_checkers:chk_not_subset(),chk_orderset(),chk_superset(),vld_not_subset()

Examples

# vld_ordersetvld_orderset(1, 1)vld_orderset(1:2, 2:1)vld_orderset(1, 2:1)vld_orderset(1:2, 2)# chk_setequalchk_setequal(1:2, 2:1)try(chk_setequal(1, 1:2))# vld_setequalvld_setequal(1, 1)vld_setequal(1:2, 2:1)vld_setequal(1, 2:1)vld_setequal(1:2, 2)

[8]ページ先頭

©2009-2025 Movatter.jp