chk/0000755000176200001440000000000014507671602011027 5ustar liggesuserschk/NAMESPACE0000644000176200001440000000661614436206156012256 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(abort_chk) export(backtick_chk) export(cc) export(check_data) export(check_dim) export(check_dirs) export(check_files) export(check_key) export(check_names) export(check_values) export(chk_all) export(chk_all_equal) export(chk_all_equivalent) export(chk_all_identical) export(chk_array) export(chk_atomic) export(chk_character) export(chk_character_or_factor) export(chk_chr) export(chk_compatible_lengths) export(chk_count) export(chk_data) export(chk_date) export(chk_date_time) export(chk_datetime) export(chk_dbl) export(chk_dir) export(chk_dirs) export(chk_double) export(chk_environment) export(chk_equal) export(chk_equivalent) export(chk_ext) export(chk_factor) export(chk_false) export(chk_file) export(chk_files) export(chk_flag) export(chk_function) export(chk_gt) export(chk_gte) export(chk_has) export(chk_identical) export(chk_in) export(chk_integer) export(chk_is) export(chk_join) export(chk_length) export(chk_lgl) export(chk_list) export(chk_logical) export(chk_lt) export(chk_lte) export(chk_match) export(chk_matrix) export(chk_missing) export(chk_named) export(chk_no_missing) export(chk_not_any_na) export(chk_not_empty) export(chk_not_missing) export(chk_not_null) export(chk_not_subset) export(chk_null) export(chk_null_or) export(chk_number) export(chk_numeric) export(chk_off) export(chk_on) export(chk_orderset) export(chk_proportion) export(chk_range) export(chk_s3_class) export(chk_s4_class) export(chk_scalar) export(chk_setequal) export(chk_sorted) export(chk_string) export(chk_subset) export(chk_superset) export(chk_true) export(chk_tz) export(chk_unique) export(chk_unused) export(chk_used) export(chk_valid_name) export(chk_vector) export(chk_whole_number) export(chk_whole_numeric) export(chk_wnum) export(chkor) export(chkor_vld) export(deparse_backtick) export(deparse_backtick_chk) export(err) export(expect_chk_error) export(is_chk_on) export(message_chk) export(msg) export(p) export(p0) export(unbacktick_chk) export(vld_all) export(vld_all_equal) export(vld_all_equivalent) export(vld_all_identical) export(vld_array) export(vld_atomic) export(vld_character) export(vld_character_or_factor) export(vld_chr) export(vld_compatible_lengths) export(vld_count) export(vld_data) export(vld_date) export(vld_date_time) export(vld_datetime) export(vld_dbl) export(vld_dir) export(vld_double) export(vld_environment) export(vld_equal) export(vld_equivalent) export(vld_ext) export(vld_factor) export(vld_false) export(vld_file) export(vld_flag) export(vld_function) export(vld_gt) export(vld_gte) export(vld_identical) export(vld_integer) export(vld_is) export(vld_join) export(vld_length) export(vld_lgl) export(vld_list) export(vld_logical) export(vld_lt) export(vld_lte) export(vld_match) export(vld_matrix) export(vld_missing) export(vld_named) export(vld_no_missing) export(vld_not_any_na) export(vld_not_empty) export(vld_not_missing) export(vld_not_null) export(vld_not_subset) export(vld_null) export(vld_number) export(vld_numeric) export(vld_orderset) export(vld_range) export(vld_s3_class) export(vld_s4_class) export(vld_scalar) export(vld_setequal) export(vld_sorted) export(vld_string) export(vld_subset) export(vld_superset) export(vld_true) export(vld_tz) export(vld_unique) export(vld_unused) export(vld_used) export(vld_valid_name) export(vld_vector) export(vld_whole_number) export(vld_whole_numeric) export(vld_wnum) export(wrn) import(lifecycle) import(rlang) chk/LICENSE0000644000176200001440000000006014507605651012031 0ustar liggesusersYEAR: 2023 COPYRIGHT HOLDER: Poisson Consulting chk/README.md0000644000176200001440000000563014506571213012306 0ustar liggesusers # chk [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) [![R-CMD-check](https://github.com/poissonconsulting/chk/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/chk/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/poissonconsulting/chk/branch/master/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/chk?branch=master) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/) [![CRAN status](https://www.r-pkg.org/badges/version/chk)](https://cran.r-project.org/package=chk) ![CRAN downloads](https://cranlogs.r-pkg.org/badges/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](https://cran.r-project.org) ``` r install.packages("chk") ``` To install the latest development version from [GitHub](https://github.com/poissonconsulting/chk) ``` r # 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. ``` r 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. ``` r 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](https://style.tidyverse.org/error-messages.html) while the errors themselves are [rlang errors](https://rlang.r-lib.org/reference/abort.html) of class `chk_error`. ## Information For more information see the [Get Started](https://poissonconsulting.github.io/chk/articles/chk.html) vignette. ## Inspiration - [datacheckr](https://github.com/poissonconsulting/datacheckr/) - [checkr](https://github.com/poissonconsulting/checkr/) - [err](https://github.com/poissonconsulting/err/) - [testthat](https://github.com/r-lib/testthat/) ## Contribution Please report any [issues](https://github.com/poissonconsulting/chk/issues). [Pull requests](https://github.com/poissonconsulting/chk/pulls) are always welcome. ## Code of Conduct Please note that the chk project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms chk/man/0000755000176200001440000000000014436206156011601 5ustar liggesuserschk/man/chk_length.Rd0000644000176200001440000000253514436206156014203 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-length.R \name{chk_length} \alias{chk_length} \alias{vld_length} \title{Check Length} \usage{ chk_length(x, length = 1L, upper = length, x_name = NULL) vld_length(x, length = 1L, upper = length) } \arguments{ \item{x}{The object to check.} \item{length}{A count of the length.} \item{upper}{A count of the max length.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks length is a particular value or range using \code{length(x) >= length && length(x) <= upper} } \section{Functions}{ \itemize{ \item \code{vld_length()}: Validate Length }} \examples{ # chk_length chk_length("text") try(vld_length("text", length = 2)) # vld_length vld_length(2:1, 2) vld_length(2:1, 1) } \seealso{ \code{\link[=check_dim]{check_dim()}} Other chk_misc: \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/cc.Rd0000644000176200001440000000203514436206156012455 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cc.R \name{cc} \alias{cc} \title{Concatenate with Commas} \usage{ cc( x, conj = ", ", sep = ", ", brac = if (is.character(x) || is.factor(x)) "'" else "", ellipsis = 10L, chk = TRUE ) } \arguments{ \item{x}{The object to concatenate.} \item{conj}{A string of the conjunction to separate the last value by.} \item{sep}{A string of the separator.} \item{brac}{A string to brac the values by.} \item{ellipsis}{A numeric scalar of the maximum number of values to display before using an ellipsis.} \item{chk}{A flag specifying whether to check the other parameters.} } \value{ A string. } \description{ Concatenates object values into a string with each value separated by a comma and the last value separated by a conjunction. } \details{ By default, if x has more than 10 values an ellipsis is used to ensure only 10 values are displayed (including the ellipsis). } \examples{ cc(1:2) cc(1:2, conj = " or") cc(3:1, brac = "'") cc(1:11) cc(as.character(1:2)) } chk/man/chk_unused.Rd0000644000176200001440000000136714436206156014227 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-unused.R \name{chk_unused} \alias{chk_unused} \alias{vld_unused} \title{Check ... Unused} \usage{ chk_unused(...) vld_unused(...) } \arguments{ \item{...}{Additional arguments.} } \value{ The \code{chk_} function throws an informative error if the test fails. } \description{ Checks if ... is unused \code{length(list(...)) == 0L} } \section{Functions}{ \itemize{ \item \code{vld_unused()}: Validate ... Unused }} \examples{ # chk_unused fun <- function(x, ...) { chk_unused(...) x } fun(1) try(fun(1, 2)) # vld_unused fun <- function(x, ...) { vld_unused(...) } fun(1) try(fun(1, 2)) } \seealso{ Other chk_ellipsis: \code{\link{chk_used}()} } \concept{chk_ellipsis} chk/man/chk-package.Rd0000644000176200001440000000253114507622000014214 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-package.R \docType{package} \name{chk-package} \alias{chk} \alias{chk-package} \title{chk: Check User-Supplied Function Arguments} \description{ \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} For developers to check user-supplied function arguments. It is designed to be simple, fast and customizable. Error messages follow the tidyverse style guide. } \seealso{ Useful links: \itemize{ \item \url{https://poissonconsulting.github.io/chk/} \item \url{https://github.com/poissonconsulting/chk/} \item Report bugs at \url{https://github.com/poissonconsulting/chk/issues/} } } \author{ \strong{Maintainer}: Joe Thorley \email{joe@poissonconsulting.ca} (\href{https://orcid.org/0000-0002-7683-4592}{ORCID}) Authors: \itemize{ \item Kirill Müller (\href{https://orcid.org/0000-0002-1416-3412}{ORCID}) \item Ayla Pearson (\href{https://orcid.org/0000-0001-7388-1222}{ORCID}) } Other contributors: \itemize{ \item Nadine Hussein \email{nadine@poissonconsulting.ca} (\href{https://orcid.org/0000-0003-4470-8361}{ORCID}) [contributor] \item Evan Amies-Galonski \email{evan@poissonconsulting.ca} (\href{https://orcid.org/0000-0003-1096-2089}{ORCID}) [contributor] \item Poisson Consulting [copyright holder, funder] } } \keyword{internal} chk/man/chk_atomic.Rd0000644000176200001440000000226014436206156014171 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-atomic.R \name{chk_atomic} \alias{chk_atomic} \alias{vld_atomic} \title{Check Atomic} \usage{ chk_atomic(x, x_name = NULL) vld_atomic(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if atomic using \code{is.atomic(x)} } \section{Functions}{ \itemize{ \item \code{vld_atomic()}: Validate Atomic }} \examples{ # chk_atomic chk_atomic(1) try(chk_atomic(list(1))) # vld_atomic vld_atomic(1) vld_atomic(matrix(1:3)) vld_atomic(character(0)) vld_atomic(list(1)) vld_atomic(NULL) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_is.Rd0000644000176200001440000000226714436206156013337 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-is.R \name{chk_is} \alias{chk_is} \alias{vld_is} \title{Check Class} \usage{ chk_is(x, class, x_name = NULL) vld_is(x, class) } \arguments{ \item{x}{The object to check.} \item{class}{A string specifying the class.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks inherits from class using \code{inherits(x, class)} } \section{Functions}{ \itemize{ \item \code{vld_is()}: Validate Inherits from Class }} \examples{ chk_is(1, "numeric") try(chk_is(1L, "double")) # vld_is vld_is(numeric(0), "numeric") vld_is(1L, "double") } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chkor.Rd0000644000176200001440000000133414436206156013177 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chkor.R \name{chkor} \alias{chkor} \title{Check OR} \usage{ chkor(...) } \arguments{ \item{...}{Multiple \code{chk_} functions.} } \value{ An informative error if the test fails. } \description{ The \code{chkor()} function has been deprecated for the faster \code{chkor_vld()}. } \details{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } \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)) } \seealso{ \code{\link[=chk_null_or]{chk_null_or()}} } chk/man/expect_chk_error.Rd0000644000176200001440000000753514436206156015430 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/expect-chk-error.R \name{expect_chk_error} \alias{expect_chk_error} \title{Expect Chk Error} \usage{ expect_chk_error( object, regexp = NULL, ..., info = NULL, label = NULL, class = NULL ) } \arguments{ \item{object}{Object to test. Supports limited unquoting to make it easier to generate readable failures within a function or for loop. See \link[testthat]{quasi_label} for more details.} \item{regexp}{Regular expression to test against. \itemize{ \item A character vector giving a regular expression that must match the error message. \item If \code{NULL}, the default, asserts that there should be an error, but doesn't test for a specific value. \item If \code{NA}, asserts that there should be no errors, but we now recommend using \code{\link[testthat:expect_no_error]{expect_no_error()}} and friends instead. } Note that you should only use \code{message} with errors/warnings/messages that you generate. Avoid tests that rely on the specific text generated by another package since this can easily change. If you do need to test text generated by another package, either protect the test with \code{skip_on_cran()} or use \code{expect_snapshot()}.} \item{...}{ Arguments passed on to \code{\link[testthat:expect_match]{expect_match}} \describe{ \item{\code{fixed}}{If \code{TRUE}, treats \code{regexp} as a string to be matched exactly (not a regular expressions). Overrides \code{perl}.} \item{\code{perl}}{logical. Should Perl-compatible regexps be used?} }} \item{info}{Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in \link[testthat]{quasi_label}.} \item{label}{Used to customise failure messages. For expert use only.} \item{class}{Must be NULL.} } \value{ If \code{regexp = NA}, the value of the first argument; otherwise the captured condition. } \description{ \code{\link[=expect_chk_error]{expect_chk_error()}} checks that code throws an error of class \code{"chk_error"} with a message that matches regexp. See below for more details. } \section{Testing \code{message} vs \code{class}}{ When checking that code generates an error, it's important to check that the error is the one you expect. There are two ways to do this. The first way is the simplest: you just provide a \code{regexp} that match some fragment of the error message. This is easy, but fragile, because the test will fail 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 at \url{https://adv-r.hadley.nz/conditions.html#custom-conditions}, but in short, errors are S3 classes and you can generate a custom class and check for it using \code{class} instead of \code{regexp}. If you are using \code{expect_error()} to check that an error message is formatted in such a way that it makes sense to a human, we recommend using \code{\link[testthat:expect_snapshot]{expect_snapshot()}} instead. } \examples{ expect_chk_error(chk_true(FALSE)) try(expect_chk_error(chk_false(FALSE))) } \seealso{ \code{\link[testthat:expect_no_error]{expect_no_error()}}, \code{expect_no_warning()}, \code{expect_no_message()}, and \code{expect_no_condition()} to assert that code runs without errors/warnings/messages/conditions. Other expectations: \code{\link[testthat]{comparison-expectations}}, \code{\link[testthat]{equality-expectations}}, \code{\link[testthat]{expect_length}()}, \code{\link[testthat]{expect_match}()}, \code{\link[testthat]{expect_named}()}, \code{\link[testthat]{expect_null}()}, \code{\link[testthat]{expect_output}()}, \code{\link[testthat]{expect_reference}()}, \code{\link[testthat]{expect_silent}()}, \code{\link[testthat]{inheritance-expectations}}, \code{\link[testthat]{logical-expectations}} } chk/man/chk_range.Rd0000644000176200001440000000264114436206156014014 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-range.R \name{chk_range} \alias{chk_range} \alias{vld_range} \title{Checks range of non-missing values} \usage{ chk_range(x, range = c(0, 1), inclusive = TRUE, x_name = NULL) vld_range(x, range = c(0, 1), inclusive = TRUE) } \arguments{ \item{x}{The object to check.} \item{range}{A non-missing sorted vector of length 2 of the lower and upper permitted values.} \item{inclusive}{A flag specifying whether the range is exclusive.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks all non-missing values fall within range using If inclusive \code{all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])} else \code{all(x[!is.na(x)] > range[1] & x[!is.na(x)] < range[2])} } \section{Functions}{ \itemize{ \item \code{vld_range()}: Validate Range }} \examples{ # chk_range chk_range(0) try(chk_range(-0.1)) # vld_range vld_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)) } \seealso{ Other chk_ranges: \code{\link{chk_gte}()}, \code{\link{chk_gt}()}, \code{\link{chk_lte}()}, \code{\link{chk_lt}()} } \concept{chk_ranges} chk/man/chk_string.Rd0000644000176200001440000000213214436206156014221 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-string.R \name{chk_string} \alias{chk_string} \alias{vld_string} \title{Check String} \usage{ chk_string(x, x_name = NULL) vld_string(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if string \code{is.character(x) && length(x) == 1L && !anyNA(x)} } \section{Functions}{ \itemize{ \item \code{vld_string()}: Validate String }} \examples{ # chk_string chk_string("1") try(chk_string(1)) # vld_string vld_string("1") vld_string("") vld_string(1) vld_string(NA_character_) vld_string(c("1", "1")) } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_date}()}, \code{\link{chk_number}()}, \code{\link{chk_scalar}()}, \code{\link{chk_tz}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_superset.Rd0000644000176200001440000000221214436206156014564 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-superset.R \name{chk_superset} \alias{chk_superset} \alias{vld_superset} \title{Check Superset} \usage{ chk_superset(x, values, x_name = NULL) vld_superset(x, values) } \arguments{ \item{x}{The object to check.} \item{values}{A vector of the permitted values.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if includes all values using \code{all(values \%in\% x)} } \section{Functions}{ \itemize{ \item \code{vld_superset()}: Validates Superset }} \examples{ # chk_superset chk_superset(1:3, 1) try(chk_superset(1:3, 4)) # vld_superset vld_superset(1:3, 1) vld_superset(1:3, 4) vld_superset(integer(0), integer(0)) } \seealso{ Other chk_set: \code{\link{chk_join}()}, \code{\link{chk_not_subset}()}, \code{\link{chk_orderset}()}, \code{\link{vld_not_subset}()}, \code{\link{vld_orderset}()} } \concept{chk_set} chk/man/chk_whole_numeric.Rd0000644000176200001440000000261114436206156015555 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-whole-numeric.R \name{chk_whole_numeric} \alias{chk_whole_numeric} \alias{vld_whole_numeric} \title{Check Whole Numeric} \usage{ chk_whole_numeric(x, x_name = NULL) vld_whole_numeric(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if integer vector or double equivalent using \code{is.integer(x) || (is.double(x) && vld_true(all.equal(x, as.integer(x))))} } \section{Functions}{ \itemize{ \item \code{vld_whole_numeric()}: Validate Whole Numeric }} \examples{ # chk_whole_numeric chk_whole_numeric(1) try(chk_whole_numeric(1.1)) # vld_whole_numeric vld_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) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()} } \concept{chk_is} chk/man/chk_whole_number.Rd0000644000176200001440000000244414436206156015407 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-whole-number.R \name{chk_whole_number} \alias{chk_whole_number} \alias{vld_whole_number} \title{Check Whole Number} \usage{ chk_whole_number(x, x_name = NULL) vld_whole_number(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-missing integer scalar or double equivalent using \code{vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))} \strong{Pass}: \code{1}, \code{2L}, \code{1e10}, \code{-Inf} \strong{Fail}: \code{"a"}, \code{1:3}, \code{NA_integer_}, \code{log(10)} } \section{Functions}{ \itemize{ \item \code{vld_whole_number()}: Validate Whole Number }} \examples{ # chk_whole_number chk_whole_number(2) try(chk_whole_number(1.1)) # vld_whole_number vld_whole_number(2) } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_date}()}, \code{\link{chk_number}()}, \code{\link{chk_scalar}()}, \code{\link{chk_string}()}, \code{\link{chk_tz}()} } \concept{chk_scalars} chk/man/abort_chk.Rd0000644000176200001440000000323714436206156014031 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R \name{abort_chk} \alias{abort_chk} \title{Abort Check} \usage{ abort_chk(..., n = NULL, tidy = TRUE, call = rlang::caller_call(2)) } \arguments{ \item{...}{Multiple objects that are converted to a string using \code{paste0(..., collapse = '')}.} \item{n}{The value of n for converting \code{sprintf}-like types.} \item{tidy}{A flag specifying whether capitalize the first character and add a missing period.} \item{call}{The execution environment of a currently running function, e.g. \code{call = caller_env()}. The corresponding function call is retrieved and mentioned in error messages as the source of the error. You only need to supply \code{call} when throwing a condition from a helper function which wouldn't be relevant to mention in the message. Can also be \code{NULL} or a \link[rlang:topic-defuse]{defused function call} to respectively not display any call or hard-code a code to display. For more information about error calls, see \ifelse{html}{\link[rlang:topic-error-call]{Including function calls in error messages}}{\link[rlang:topic-error-call]{Including function calls in error messages}}.} } \value{ Throws an error of class \code{'chk_error'}. } \description{ A wrapper on \code{\link[=err]{err()}} that sets the subclass to be \code{'chk_error'}. } \details{ It is exported to allow users to easily construct their own \code{chk_} functions. } \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)) } \seealso{ \code{\link[=err]{err()}} } chk/man/chk_dbl.Rd0000644000176200001440000000244214436206156013460 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-dbl.R \name{chk_dbl} \alias{chk_dbl} \alias{vld_dbl} \title{Check Double Scalar} \usage{ chk_dbl(x, x_name = NULL) vld_dbl(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if double scalar using \code{is.double(x) && length(x) == 1L} \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } \section{Functions}{ \itemize{ \item \code{vld_dbl()}: Validate Double \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} }} \examples{ # chk_dbl chk_dbl(1) try(chk_dbl(1L)) # vld_dbl vld_dbl(1) vld_dbl(double(0)) vld_dbl(NA_real_) vld_dbl(c(1, 1)) vld_dbl(1L) } \seealso{ Other deprecated: \code{\link{chk_chr}()}, \code{\link{chk_deprecated}}, \code{\link{chk_wnum}()} } \concept{deprecated} chk/man/chk_null.Rd0000644000176200001440000000151314436206156013667 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-null.R \name{chk_null} \alias{chk_null} \alias{vld_null} \title{Check NULL} \usage{ chk_null(x, x_name = NULL) vld_null(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if NULL using \code{is.null(x)} } \section{Functions}{ \itemize{ \item \code{vld_null()}: Validate NULL }} \examples{ # chk_null try(chk_null(1)) chk_null(NULL) # vld_null vld_null(NULL) vld_null(1) } \seealso{ Other chk_nulls: \code{\link{chk_not_null}()} } \concept{chk_nulls} chk/man/chk_named.Rd0000644000176200001440000000227514436206156014007 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-named.R \name{chk_named} \alias{chk_named} \alias{vld_named} \title{Check Named} \usage{ chk_named(x, x_name = NULL) vld_named(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is named using \code{!is.null(names(x))} } \section{Functions}{ \itemize{ \item \code{vld_named()}: Validate Named }} \examples{ # chk_named chk_named(c(x = 1)) try(chk_named(list(1))) # vld_named vld_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)) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chkor_vld.Rd0000644000176200001440000000142614436206156014046 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chkor-vld.R \name{chkor_vld} \alias{chkor_vld} \title{Chk OR} \usage{ chkor_vld(...) } \arguments{ \item{...}{Multiple \code{vld_} calls. A common mistake is to pass \code{chk_} calls. \code{chkor_vld()} is relatively slow. If at all possible use \code{\link[=chk_null_or]{chk_null_or()}} or first test using the individual \code{vld_} functions and then call \code{chkor_vld()} to generate an informative error message.} } \value{ An informative error if the test fails. } \description{ Chk 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)) } \seealso{ \code{\link[=chk_null_or]{chk_null_or()}} } chk/man/check_key.Rd0000644000176200001440000000163514436206156014022 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-key.R \name{check_key} \alias{check_key} \title{Check Key} \usage{ check_key(x, key = character(0), na_distinct = FALSE, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{key}{A character vector of the columns that represent a unique key.} \item{na_distinct}{A flag specifying whether missing values should be considered distinct.} \item{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. } \description{ Checks if columns have unique rows. } \examples{ x <- data.frame(x = c(1, 2), y = c(1, 1)) check_key(x) try(check_key(x, "y")) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dim}()}, \code{\link{check_dirs}()}, \code{\link{check_files}()}, \code{\link{check_names}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_lte.Rd0000644000176200001440000000220014436206156013473 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-lte.R \name{chk_lte} \alias{chk_lte} \alias{vld_lte} \title{Check Less Than or Equal To} \usage{ chk_lte(x, value = 0, x_name = NULL) vld_lte(x, value = 0) } \arguments{ \item{x}{The object to check.} \item{value}{A non-missing scalar of a value.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all non-missing values are less than or equal to y using \code{all(x[!is.na(x)] <= value)} } \section{Functions}{ \itemize{ \item \code{vld_lte()}: Validate Less Than or Equal To }} \examples{ # chk_lte chk_lte(0) try(chk_lte(0.1)) # vld_lte vld_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) } \seealso{ Other chk_ranges: \code{\link{chk_gte}()}, \code{\link{chk_gt}()}, \code{\link{chk_lt}()}, \code{\link{chk_range}()} } \concept{chk_ranges} chk/man/chk_equivalent.Rd0000644000176200001440000000240714436206156015075 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-equivalent.R \name{chk_equivalent} \alias{chk_equivalent} \alias{vld_equivalent} \title{Check Equivalent} \usage{ chk_equivalent(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL) vld_equivalent(x, y, tolerance = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{The object to check.} \item{y}{An object to check against.} \item{tolerance}{A non-negative numeric scalar.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is equivalent (equal ignoring attributes) to y using \code{vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))} } \section{Functions}{ \itemize{ \item \code{vld_equivalent()}: Validate Equivalent }} \examples{ # chk_equivalent chk_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)) } \seealso{ Other chk_equals: \code{\link{chk_equal}()}, \code{\link{chk_identical}()} } \concept{chk_equals} chk/man/chk_function.Rd0000644000176200001440000000252214436206156014543 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-function.R \name{chk_function} \alias{chk_function} \alias{vld_function} \title{Check Function} \usage{ chk_function(x, formals = NULL, x_name = NULL) vld_function(x, formals = NULL) } \arguments{ \item{x}{The object to check.} \item{formals}{A count of the number of formal arguments.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is a function using \code{is.function(x) && (is.null(formals) || length(formals(x)) == formals)} } \section{Functions}{ \itemize{ \item \code{vld_function()}: Validate Function }} \examples{ # chk_function chk_function(mean) try(chk_function(1)) # vld_function vld_function(mean) vld_function(function(x) x) vld_function(1) vld_function(list(1)) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_subset.Rd0000644000176200001440000000251114436206156014221 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-subset.R, R/chk-subset.R \name{vld_not_subset} \alias{vld_not_subset} \alias{chk_subset} \alias{vld_subset} \title{Check Subset} \usage{ vld_not_subset(x, values) chk_subset(x, values, x_name = NULL) vld_subset(x, values) } \arguments{ \item{x}{The object to check.} \item{values}{A vector of the permitted values.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all values in values using \code{all(x \%in\% values)} } \section{Functions}{ \itemize{ \item \code{vld_not_subset()}: Validate Not Subset \item \code{vld_subset()}: Validate Subset }} \examples{ # vld_not_subset vld_not_subset(numeric(0), 1:10) vld_not_subset(1, 1:10) vld_not_subset(11, 1:10) # chk_subset chk_subset(1, 1:10) try(chk_subset(11, 1:10)) # vld_subset vld_subset(numeric(0), 1:10) vld_subset(1, 1:10) vld_subset(11, 1:10) } \seealso{ Other chk_set: \code{\link{chk_join}()}, \code{\link{chk_not_subset}()}, \code{\link{chk_orderset}()}, \code{\link{chk_superset}()}, \code{\link{vld_orderset}()} } \concept{chk_set} chk/man/chk_orderset.Rd0000644000176200001440000000200114436206156014535 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-orderset.R \name{chk_orderset} \alias{chk_orderset} \title{Check Set Ordered} \usage{ chk_orderset(x, values, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{values}{A vector of the permitted values.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if the first occurrence of each shared element in x is equivalent to the first occurrence of each shared element in values using \code{vld_equivalent(unique(x[x \%in\% values]), values[values \%in\% x])}. } \examples{ # chk_orderset chk_orderset(1:2, 1:2) try(chk_orderset(2:1, 1:2)) } \seealso{ Other chk_set: \code{\link{chk_join}()}, \code{\link{chk_not_subset}()}, \code{\link{chk_superset}()}, \code{\link{vld_not_subset}()}, \code{\link{vld_orderset}()} } \concept{chk_set} chk/man/chk_array.Rd0000644000176200001440000000215714436206156014040 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-array.R \name{chk_array} \alias{chk_array} \alias{vld_array} \title{Check Array} \usage{ chk_array(x, x_name = NULL) vld_array(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is an array using \code{is.array(x)} } \section{Functions}{ \itemize{ \item \code{vld_array()}: Validate Array }} \examples{ # chk_array chk_array(array(1)) try(chk_array(matrix(1))) # vld_array vld_array(1) vld_array(array(1)) } \seealso{ Other chk_is: \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_matrix.Rd0000644000176200001440000000217614436206156014227 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-matrix.R \name{chk_matrix} \alias{chk_matrix} \alias{vld_matrix} \title{Check Matrix} \usage{ chk_matrix(x, x_name = NULL) vld_matrix(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is a matrix using \code{is.matrix(x)} } \section{Functions}{ \itemize{ \item \code{vld_matrix()}: Validate Matrix }} \examples{ # chk_matrix chk_matrix(matrix(1)) try(chk_matrix(array(1))) # vld_matrix vld_matrix(1) vld_matrix(matrix(1)) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_file.Rd0000644000176200001440000000161714436206156013641 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-file.R \name{chk_file} \alias{chk_file} \alias{vld_file} \title{Check File Exists} \usage{ chk_file(x, x_name = NULL) vld_file(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if file exists using \code{vld_string(x) && file.exists(x) && !dir.exists(x)} } \section{Functions}{ \itemize{ \item \code{vld_file()}: Validate File Exists }} \examples{ # chk_file try(chk_file(tempfile())) # vld_file vld_file(tempfile()) } \seealso{ Other chk_files: \code{\link{chk_dir}()}, \code{\link{chk_ext}()} } \concept{chk_files} chk/man/params.Rd0000644000176200001440000000411714436206156013356 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/template.R \name{params} \alias{params} \title{Parameters for chk functions} \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} \item{y}{An object to check against.} \item{chk}{A flag specifying whether to check the other parameters.} \item{chk_fun}{A chk_ function.} \item{tolerance}{A non-negative numeric scalar.} \item{ext}{A character vector of the permitted file extensions (without the .).} \item{exists}{A flag specifying whether the files/directories must (or must not) exist.} \item{value}{A non-missing scalar of a value.} \item{range}{A non-missing sorted vector of length 2 of the lower and upper permitted values.} \item{inclusive}{A flag specifying whether the range is exclusive.} \item{regexp}{A string of a regular expression.} \item{values}{A vector of the permitted values.} \item{class}{A string specifying the class.} \item{length}{A count of the length.} \item{upper}{A count of the max length.} \item{formals}{A count of the number of formal arguments.} \item{incomparables}{A vector of values that cannot be compared. FALSE means that all values can be compared.} \item{by}{A character vector specifying the column names to join x and y on. If named the names are the corresponding columns in x.} \item{exclusive}{A flag specifying whether x must only include columns named in values.} \item{order}{A flag specifying whether the order of columns in x must match names in values.} \item{nrow}{A flag or a whole numeric vector of the value, value range or possible values.} \item{key}{A character vector of the columns that represent a unique key.} \item{vld_fun}{A vld_ function.} \item{...}{Additional arguments.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Descriptions of the parameters and return values for the chk functions } \keyword{internal} chk/man/chk_missing.Rd0000644000176200001440000000240714436206156014371 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-missing.R \name{chk_missing} \alias{chk_missing} \alias{vld_missing} \title{Check Missing Argument} \usage{ chk_missing(x, x_name = NULL) vld_missing(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks argument missing using \code{missing(x)} } \details{ Currently only checks if value is available (as opposed to whether it was specified). } \section{Functions}{ \itemize{ \item \code{vld_missing()}: Validate Missing Argument }} \examples{ # chk_missing fun <- function(x) { chk_missing(x) } fun() try(fun(1)) # vld_missing fun <- function(x) { vld_missing(x) } fun() fun(1) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_all_equivalent.Rd0000644000176200001440000000255114436206156015725 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-all-equivalent.R \name{chk_all_equivalent} \alias{chk_all_equivalent} \alias{vld_all_equivalent} \title{Check All Equivalent} \usage{ chk_all_equivalent(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL) vld_all_equivalent(x, tolerance = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{The object to check.} \item{tolerance}{A non-negative numeric scalar.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks all elements in x equivalent using \code{length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance))} } \section{Functions}{ \itemize{ \item \code{vld_all_equivalent()}: Validate All Equivalent }} \examples{ # chk_all_equivalent chk_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_equivalent vld_all_equivalent(c(x = 1, y = 1)) } \seealso{ Other chk_alls: \code{\link{chk_all_equal}()}, \code{\link{chk_all_identical}()}, \code{\link{chk_all}()} } \concept{chk_alls} chk/man/chk_gte.Rd0000644000176200001440000000220614436206156013474 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-gte.R \name{chk_gte} \alias{chk_gte} \alias{vld_gte} \title{Check Greater Than or Equal To} \usage{ chk_gte(x, value = 0, x_name = NULL) vld_gte(x, value = 0) } \arguments{ \item{x}{The object to check.} \item{value}{A non-missing scalar of a value.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all non-missing values are greater than or equal to y using \code{all(x[!is.na(x)] >= value)} } \section{Functions}{ \itemize{ \item \code{vld_gte()}: Validate Greater Than or Equal To }} \examples{ # chk_gte chk_gte(0) try(chk_gte(-0.1)) # vld_gte vld_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) } \seealso{ Other chk_ranges: \code{\link{chk_gt}()}, \code{\link{chk_lte}()}, \code{\link{chk_lt}()}, \code{\link{chk_range}()} } \concept{chk_ranges} chk/man/chk_dir.Rd0000644000176200001440000000166214436206156013500 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-dir.R \name{chk_dir} \alias{chk_dir} \alias{vld_dir} \title{Check Directory Exists} \usage{ chk_dir(x, x_name = NULL) vld_dir(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if directory exists using \code{vld_string(x) && dir.exists(x)} } \section{Functions}{ \itemize{ \item \code{vld_dir()}: Validate Directory Exists }} \examples{ # chk_dir chk_dir(tempdir()) try(chk_dir(tempfile())) # vld_dir vld_dir(1) vld_dir(tempdir()) vld_dir(tempfile()) } \seealso{ Other chk_files: \code{\link{chk_ext}()}, \code{\link{chk_file}()} } \concept{chk_files} chk/man/p.Rd0000644000176200001440000000146614436206156012336 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/p.R \name{p} \alias{p} \alias{p0} \title{Concatenate Strings} \usage{ p(..., sep = " ", collapse = NULL) p0(..., collapse = NULL) } \arguments{ \item{...}{one or more \R objects, to be converted to character vectors.} \item{sep}{a character string to separate the terms. Not \code{\link[base]{NA_character_}}.} \item{collapse}{an optional character string to separate the results. Not \code{\link[base]{NA_character_}}.} } \value{ A character vector. } \description{ A wrapper on \code{\link[base:paste]{base::paste()}}. } \section{Functions}{ \itemize{ \item \code{p0()}: A wrapper on \code{\link[base:paste]{base::paste0()}} }} \examples{ p("a", "b") p(c("a", "b"), collapse = " ") p0("a", "b") p0(c("a", "b"), collapse = "") } chk/man/chk_compatible_lengths.Rd0000644000176200001440000000337014436206156016563 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-compatible-lengths.R \name{chk_compatible_lengths} \alias{chk_compatible_lengths} \alias{vld_compatible_lengths} \title{Check Compatible Lengths} \usage{ chk_compatible_lengths(..., x_name = NULL) vld_compatible_lengths(...) } \arguments{ \item{...}{The objects to check for compatible lengths.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails. } \description{ Checks objects (including vectors) have lengths that could be 'strictly recycled'. That is to say they must all be either zero length or the same length with some of length 1. } \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 and length 4, even though the vector of length 2 could be 'loosely recycled' to match up to the vector of length 4 when combined. The intent of the function is to check that only strict recycling is occurring. } \section{Functions}{ \itemize{ \item \code{vld_compatible_lengths()}: Validate Compatible Lengths }} \examples{ # chk_compatible_lengths a <- integer(0) b <- numeric(0) chk_compatible_lengths(a, b) a <- 1 b <- 2 chk_compatible_lengths(a, b) a <- 1:3 b <- 1:3 chk_compatible_lengths(a, b) b <- 1 chk_compatible_lengths(a, b) b <- 1:2 try(chk_compatible_lengths(a, b)) b <- 1:6 try(chk_compatible_lengths(a, b)) # vld_compatible_lengths a <- integer(0) b <- numeric(0) vld_compatible_lengths(a, b) a <- 1 b <- 2 vld_compatible_lengths(a, b) a <- 1:3 b <- 1:3 vld_compatible_lengths(a, b) b <- 1 vld_compatible_lengths(a, b) b <- 1:2 vld_compatible_lengths(a, b) b <- 1:6 vld_compatible_lengths(a, b) } chk/man/chk_all.Rd0000644000176200001440000000213714436206156013470 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-all.R \name{chk_all} \alias{chk_all} \alias{vld_all} \title{Check All} \usage{ chk_all(x, chk_fun, ..., x_name = NULL) vld_all(x, vld_fun, ...) } \arguments{ \item{x}{The object to check.} \item{chk_fun}{A chk_ function.} \item{...}{Additional arguments.} \item{x_name}{A string of the name of object x or NULL.} \item{vld_fun}{A vld_ function.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks all elements using \code{all(vapply(x, chk_fun, TRUE, ...))} } \section{Functions}{ \itemize{ \item \code{vld_all()}: Validate All }} \examples{ # chk_all chk_all(TRUE, chk_lgl) # FIXME try(chk_all(1, chk_lgl)) chk_all(c(TRUE, NA), chk_lgl) # vld_all vld_all(c(TRUE, NA), vld_lgl) } \seealso{ Other chk_alls: \code{\link{chk_all_equal}()}, \code{\link{chk_all_equivalent}()}, \code{\link{chk_all_identical}()} } \concept{chk_alls} chk/man/chk_double.Rd0000644000176200001440000000230114436206156014163 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-double.R \name{chk_double} \alias{chk_double} \alias{vld_double} \title{Check Double} \usage{ chk_double(x, x_name = NULL) vld_double(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if double using \code{is.double(x)} } \section{Functions}{ \itemize{ \item \code{vld_double()}: Validate Double }} \examples{ # chk_double chk_double(1) try(chk_double(1L)) # vld_double vld_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) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_tz.Rd0000644000176200001440000000204314436206156013351 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-tz.R \name{chk_tz} \alias{chk_tz} \alias{vld_tz} \title{Check Time Zone} \usage{ chk_tz(x, x_name = NULL) vld_tz(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-missing valid scalar timezone using \code{is.character(x) && length(x) == 1L && !anyNA(x) && x \%in\% OlsonNames()} } \section{Functions}{ \itemize{ \item \code{vld_tz()}: Validate Time Zone }} \examples{ chk_tz("UTC") try(chk_tz("TCU")) vld_tz("UTC") vld_tz("TCU") } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_date}()}, \code{\link{chk_number}()}, \code{\link{chk_scalar}()}, \code{\link{chk_string}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_all_identical.Rd0000644000176200001440000000230214436206156015476 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-all-identical.R \name{chk_all_identical} \alias{chk_all_identical} \alias{vld_all_identical} \title{Check All Identical} \usage{ chk_all_identical(x, x_name = NULL) vld_all_identical(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks all elements in x identical using \code{length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]]))} \strong{Pass}: \code{c(1, 1, 1)}, \code{list(1, 1)} \strong{Fail}: \code{c(1, 1.0000001)}, \code{list(1, NA)} } \section{Functions}{ \itemize{ \item \code{vld_all_identical()}: Validate All Identical }} \examples{ # chk_all_identical chk_all_identical(c(1, 1)) try(chk_all_identical(c(1, 1.1))) # vld_all_identical vld_all_identical(c(1, 1)) } \seealso{ Other chk_alls: \code{\link{chk_all_equal}()}, \code{\link{chk_all_equivalent}()}, \code{\link{chk_all}()} } \concept{chk_alls} chk/man/chk_used.Rd0000644000176200001440000000133614436206156013660 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-used.R \name{chk_used} \alias{chk_used} \alias{vld_used} \title{Check ... Used} \usage{ chk_used(...) vld_used(...) } \arguments{ \item{...}{Additional arguments.} } \value{ The \code{chk_} function throws an informative error if the test fails. } \description{ Checks if is ... used using \code{length(list(...)) != 0L} } \section{Functions}{ \itemize{ \item \code{vld_used()}: Validate ... Used }} \examples{ # chk_used fun <- function(x, ...) { chk_used(...) x } try(fun(1)) fun(1, 2) # vld_used fun <- function(x, ...) { vld_used(...) } fun(1) fun(1, 2) } \seealso{ Other chk_ellipsis: \code{\link{chk_unused}()} } \concept{chk_ellipsis} chk/man/check_values.Rd0000644000176200001440000000306314436206156014526 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-values.R \name{check_values} \alias{check_values} \title{Check Values and Class} \usage{ check_values(x, values, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{values}{An atomic vector specifying the S3 class and possible values.} \item{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. } \description{ Checks values and S3 class of an atomic object. } \details{ To check the class simply pass a vector of the desired class. To check that x does not include missing values pass a 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 pass a 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 values pass three or more non-missing values. In the case of a factor ensure values has two levels to check that the levels of x are an ordered superset of the levels of value and three or more levels to check that they are identical. } \examples{ check_values(1, numeric(0)) check_values(1, 2) try(check_values(1, 1L)) try(check_values(NA_real_, 1)) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dim}()}, \code{\link{check_dirs}()}, \code{\link{check_files}()}, \code{\link{check_key}()}, \code{\link{check_names}()} } \concept{check} chk/man/chk_not_null.Rd0000644000176200001440000000161014436206156014545 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-null.R \name{chk_not_null} \alias{chk_not_null} \alias{vld_not_null} \title{Check not NULL} \usage{ chk_not_null(x, x_name = NULL) vld_not_null(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if not NULL using \code{!is.null(x)} } \section{Functions}{ \itemize{ \item \code{vld_not_null()}: Validate Not NULL }} \examples{ # chk_not_null try(chk_not_null(NULL)) chk_not_null(1) # vld_not_null vld_not_null(1) vld_not_null(NULL) } \seealso{ Other chk_nulls: \code{\link{chk_null}()} } \concept{chk_nulls} chk/man/chk_unique.Rd0000644000176200001440000000267214436206156014232 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-unique.R \name{chk_unique} \alias{chk_unique} \alias{vld_unique} \title{Check Unique} \usage{ chk_unique(x, incomparables = FALSE, x_name = NULL) vld_unique(x, incomparables = FALSE) } \arguments{ \item{x}{The object to check.} \item{incomparables}{A vector of values that cannot be compared. FALSE means that all values can be compared.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if unique using \code{!anyDuplicated(x, incomparables = incomparables)} } \section{Functions}{ \itemize{ \item \code{vld_unique()}: Validate Unique }} \examples{ # chk_unique chk_unique(c(NA, 2)) try(chk_unique(c(NA, NA, 2))) chk_unique(c(NA, NA, 2), incomparables = NA) # vld_unique vld_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) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_wnum.Rd0000644000176200001440000000260614436206156013707 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-wnum.R \name{chk_wnum} \alias{chk_wnum} \alias{vld_wnum} \title{Check Whole Numeric Scalar} \usage{ chk_wnum(x, x_name = NULL) vld_wnum(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if whole numeric scalar using \code{is.numeric(x) && length(x) == 1L && (is.integer(x) || vld_true(all.equal(x, trunc(x))))} \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } \section{Functions}{ \itemize{ \item \code{vld_wnum()}: Validate Whole Numeric Scalar \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} }} \examples{ # chk_wnum chk_wnum(1) try(chk_wnum(1.1)) # vld_wnum vld_wnum(1) vld_wnum(double(0)) vld_wnum(NA_real_) vld_wnum(c(1, 1)) vld_wnum(1L) } \seealso{ Other deprecated: \code{\link{chk_chr}()}, \code{\link{chk_dbl}()}, \code{\link{chk_deprecated}} } \concept{deprecated} chk/man/deparse_backtick_chk.Rd0000644000176200001440000000153314436206156016175 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R \name{deparse_backtick_chk} \alias{deparse_backtick_chk} \alias{backtick_chk} \alias{unbacktick_chk} \title{Deparse Backtick} \usage{ deparse_backtick_chk(x) backtick_chk(x) unbacktick_chk(x) } \arguments{ \item{x}{A substituted object to deparse.} } \value{ A string of the backticked substituted object. } \description{ \code{deparse_backtick_chk} is a wrapper on \code{\link[=deparse]{deparse()}} and \code{backtick_chk}. } \details{ It is exported to allow users to easily construct their own \code{chk_} functions. } \section{Functions}{ \itemize{ \item \code{backtick_chk()}: Backtick \item \code{unbacktick_chk()}: Unbacktick }} \examples{ # deparse_backtick_chk deparse_backtick_chk(2) deparse_backtick_chk(2^2) } \seealso{ \code{\link[=deparse]{deparse()}} } chk/man/chk_logical.Rd0000644000176200001440000000225314436206156014331 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-logical.R \name{chk_logical} \alias{chk_logical} \alias{vld_logical} \title{Check Logical} \usage{ chk_logical(x, x_name = NULL) vld_logical(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if logical using \code{is.logical(x)} } \section{Functions}{ \itemize{ \item \code{vld_logical()}: Validate Logical }} \examples{ # chk_logical chk_logical(TRUE) try(chk_logical(1)) # vld_logical vld_logical(TRUE) vld_logical(matrix(TRUE)) vld_logical(logical(0)) vld_logical(NA) vld_logical(1) vld_logical("TRUE") } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()} } \concept{chk_typeof} chk/man/message_chk.Rd0000644000176200001440000000242314436206156014342 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/err.R \name{message_chk} \alias{message_chk} \title{Construct Tidyverse Style Message} \usage{ message_chk(..., n = NULL, tidy = TRUE) } \arguments{ \item{...}{Multiple objects that are converted to a string using \code{paste0(..., collapse = '')}.} \item{n}{The value of n for converting \code{sprintf}-like types.} \item{tidy}{A flag specifying whether capitalize the first character and add a missing period.} } \value{ A string of the message. } \description{ If \code{tidy = TRUE} constructs a tidyverse style message by } \details{ \itemize{ \item Capitalizing the first character if possible. \item Adding a trailing . if missing. } Also if \code{n != NULL} replaces the recognized \code{sprintf}-like types. } \section{\code{sprintf}-like types}{ The following recognized \code{sprintf}-like types can be used in a message: \describe{ \item{\code{n}}{The value of n.} \item{\code{s}}{'' if n == 1 otherwise 's'} \item{\code{r}}{'is' if n == 1 otherwise 'are'} \item{\code{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) } chk/man/chk_sorted.Rd0000644000176200001440000000215514436206156014220 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-sorted.R \name{chk_sorted} \alias{chk_sorted} \alias{vld_sorted} \title{Check Sorted} \usage{ chk_sorted(x, x_name = NULL) vld_sorted(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is sorted using \code{is.unsorted(x, na.rm = TRUE)} } \section{Functions}{ \itemize{ \item \code{vld_sorted()}: Validate Sorted }} \examples{ # chk_sorted chk_sorted(1:2) try(chk_sorted(2:1)) # vld_sorted vld_sorted(1:2) vld_sorted(2:1) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_not_any_na.Rd0000644000176200001440000000260514436206156015045 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-any-na.R \name{chk_not_any_na} \alias{chk_not_any_na} \alias{vld_not_any_na} \title{Check Not Any Missing Values} \usage{ chk_not_any_na(x, x_name = NULL) vld_not_any_na(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if not any missing values using \code{!anyNA(x)} \strong{Pass}: \code{1}, \code{1:2}, \code{"1"}, \code{logical(0)}. \strong{Fail}: \code{NA}, \code{c(1, NA)}. } \section{Functions}{ \itemize{ \item \code{vld_not_any_na()}: Validate Not Any Missing Values }} \examples{ # chk_not_any_na chk_not_any_na(1) try(chk_not_any_na(NA)) # vld_not_any_na vld_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) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_null_or.Rd0000644000176200001440000000144214436206156014370 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-null-or.R \name{chk_null_or} \alias{chk_null_or} \title{Check NULL Or} \usage{ chk_null_or(x, chk, ..., vld, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{chk}{A chk function. Soft-deprecated for vld. \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}} \item{...}{Arguments passed to chk.} \item{vld}{A vld function.} \item{x_name}{A string of the name of object x or NULL.} } \value{ An informative error if the test fails. } \description{ Checks if NULL or passes test. } \examples{ chk_null_or(NULL, chk_number) chk_null_or(1, chk_number) try(chk_null_or("1", chk_number)) } chk/man/chk_factor.Rd0000644000176200001440000000217414436206156014177 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-factor.R \name{chk_factor} \alias{chk_factor} \alias{vld_factor} \title{Check Factor} \usage{ chk_factor(x, x_name = NULL) vld_factor(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if factor using \code{is.factor(x)} } \section{Functions}{ \itemize{ \item \code{vld_factor()}: Validate Factor }} \examples{ # chk_factor chk_factor(factor("1")) try(chk_factor("1")) # vld_factor vld_factor(factor("1")) vld_factor(factor(0)) vld_factor("1") vld_factor(1L) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_scalar.Rd0000644000176200001440000000201014436206156014153 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-scalar.R \name{chk_scalar} \alias{chk_scalar} \alias{vld_scalar} \title{Check Scalar} \usage{ chk_scalar(x, x_name = NULL) vld_scalar(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is a vector using \code{length(x) == 1L} } \section{Functions}{ \itemize{ \item \code{vld_scalar()}: Validate Scalar }} \examples{ # chk_scalar chk_scalar(1) chk_scalar(list(1)) try(chk_scalar(1:2)) # vld_scalar vld_scalar(1) } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_date}()}, \code{\link{chk_number}()}, \code{\link{chk_string}()}, \code{\link{chk_tz}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_chr.Rd0000644000176200001440000000250714436206156013475 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-chr.R \name{chk_chr} \alias{chk_chr} \alias{vld_chr} \title{Check Character Scalar} \usage{ chk_chr(x, x_name = NULL) vld_chr(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if character scalar using \code{is.character(x) && length(x) == 1L} \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } \section{Functions}{ \itemize{ \item \code{vld_chr()}: Validate Character Scalar \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} }} \examples{ chk_chr("a") try(chk_chr(1)) # vld_chr vld_chr("") vld_chr("a") vld_chr(NA_character_) vld_chr(c("a", "b")) vld_chr(1) } \seealso{ Other deprecated: \code{\link{chk_dbl}()}, \code{\link{chk_deprecated}}, \code{\link{chk_wnum}()} } \concept{chk_character} \concept{deprecated} chk/man/chk_character_or_factor.Rd0000644000176200001440000000275414436206156016717 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-character-or-factor.R \name{chk_character_or_factor} \alias{chk_character_or_factor} \alias{vld_character_or_factor} \title{Check Character or Factor} \usage{ chk_character_or_factor(x, x_name = NULL) vld_character_or_factor(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if character or factor using \code{is.character(x) || is.factor(x)} } \section{Functions}{ \itemize{ \item \code{vld_character_or_factor()}: Validate Character or Factor }} \examples{ # chk_character_or_factor chk_character_or_factor("1") chk_character_or_factor(factor("1")) try(chk_character(1)) # vld_character_or_factor vld_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")) } \seealso{ Other chk_typeof: \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_not_empty.Rd0000644000176200001440000000266514436206156014744 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-empty.R \name{chk_not_empty} \alias{chk_not_empty} \alias{vld_not_empty} \title{Check Not Empty} \usage{ chk_not_empty(x, x_name = NULL) vld_not_empty(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if not empty using \code{length(x) != 0L} \strong{Pass}: \code{1}, \code{1:2}, \code{NA}, \code{matrix(1:3)}, \code{list(1)}, \code{data.frame(x = 1)}. \strong{Fail}: \code{NULL}, \code{logical(0)}, \code{list()}, \code{data.frame()}. } \section{Functions}{ \itemize{ \item \code{vld_not_empty()}: Validate Not Empty }} \examples{ # chk_not_empty chk_not_empty(1) try(chk_not_empty(numeric(0))) # vld_not_empty vld_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()) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/err.Rd0000644000176200001440000000416114436206156012662 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/err.R \name{err} \alias{err} \alias{wrn} \alias{msg} \title{Stop, Warning and Message Messages} \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{ \item{...}{zero or more objects which can be coerced to character (and which are pasted together with no separator) or a single condition object.} \item{n}{The value of n for converting \code{sprintf}-like types.} \item{tidy}{A flag specifying whether capitalize the first character and add a missing period.} \item{.subclass}{A string of the class of the error message.} \item{class}{Subclass of the condition.} \item{call}{The execution environment of a currently running function, e.g. \code{call = caller_env()}. The corresponding function call is retrieved and mentioned in error messages as the source of the error. You only need to supply \code{call} when throwing a condition from a helper function which wouldn't be relevant to mention in the message. Can also be \code{NULL} or a \link[rlang:topic-defuse]{defused function call} to respectively not display any call or hard-code a code to display. For more information about error calls, see \ifelse{html}{\link[rlang:topic-error-call]{Including function calls in error messages}}{\link[rlang:topic-error-call]{Including function calls in error messages}}.} } \description{ The functions call \code{\link[=message_chk]{message_chk()}} to process the message and then \code{\link[rlang:abort]{rlang::abort()}}, \code{\link[rlang:abort]{rlang::warn()}} and \code{\link[rlang:abort]{rlang::inform()}}, respectively. } \details{ The user can set the subclass. } \section{Functions}{ \itemize{ \item \code{err()}: Error \item \code{wrn()}: Warning \item \code{msg()}: Message }} \examples{ # err try(err("there \%r \%n problem value\%s", n = 2)) # wrn wrn("there \%r \%n problem value\%s", n = 2) # msg msg("there \%r \%n problem value\%s", n = 2) } chk/man/chk_list.Rd0000644000176200001440000000214414436206156013671 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-list.R \name{chk_list} \alias{chk_list} \alias{vld_list} \title{Check List} \usage{ chk_list(x, x_name = NULL) vld_list(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is a list using \code{is.list(x)} } \section{Functions}{ \itemize{ \item \code{vld_list()}: Validate List }} \examples{ # chk_list chk_list(list()) try(chk_list(1)) # vld_list vld_list(list()) vld_list(list(x = 1)) vld_list(mtcars) vld_list(1) vld_list(NULL) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/figures/0000755000176200001440000000000014436206156013245 5ustar liggesuserschk/man/figures/lifecycle-defunct.svg0000644000176200001440000000170414436206156017355 0ustar liggesuserslifecyclelifecycledefunctdefunct chk/man/figures/lifecycle-maturing.svg0000644000176200001440000000170614436206156017555 0ustar liggesuserslifecyclelifecyclematuringmaturing chk/man/figures/logo.png0000644000176200001440000000546214436206156014722 0ustar liggesusersPNG  IHDRxa>tEXtSoftwareAdobe ImageReadyqe< IDATxSEǻBYdI%VI<%*/L*p 9y*\`YE)+KJa\$,Bfٝ陝yj2Pig}_Xg䱥yJy},6<)K`n\l=p/L#63 6_[N۠X_5:දX/cvuv[G^,| v몳mmm칾^}{ {*)flгXΎCW=͎^Ћ.-}Y}`Ⰺ Ug:;Ynur=M6wmnm3)ݰ窗D}ѓd6)*nؼc^m}GP| й*ǖ>/eؠ8:OاA uS^%p v5ܝEaiO찗gGĐjAD(KJcu5dnʒ<"zy](p:%y`[.%N{ZKU!augeI0+0(`JԬ=4cMyʄ{]ء {ռ' ;yko*dwj{S!` K poo!I闳 Lp 0%7Հ[2[2 [2 q[2qEr25VF Y#ik`Yikdr;LvF':d рBN\6, 9p rZ& p3i8IM'geV6X-szpM5bXYֳ?YXtܣٻpZƢ"&j\n/nuL5];΢kVq}l-3YCrצmY1^wU(NpVr\iUبWMì䆭6<4I0*må `2L0&#d`t?zCoK5'CoK0&k1 ѱtʿllW\)oMƷ``=<&*y>dn<SO}~i)6}+ܷ^<*Γa6`p۸ @1x.~_me_ݼgZyL׿7Ňpq Z݄E,z ^mzPF0VYzpK;\kƬaˆ`_r_ܵ^CRop뿮jvR6uo[K>>Яդ0'葁:ćUx_Kg?addtf_l{.Zm}Nװ;l&*T!BS cX~?\k?fB?F-YNq3 @' ߘ_c73ЂD90ئN}l@nnA@#">;}P]qcCg7|Ώ*\WU&P!W RP;yT7&@;nU:;-Kne:+:x7iѮcY2" %YȊ\M #mS֟j>ҋ;uqAA罆U&-gފ^+^`Wx%kUq%lsk[l)P/рkV'bɏN51pݰj\VU%-2^j׀.0˒*Ӌ\㶵*K(&d/k@YiϨx\˒*xx>G^%:uzY22v^*$ni8xXN%.`yоʒp,iq-UY%e<hd*-p@C?Ҟf `}UfcLx? _9IENDB`chk/man/figures/lifecycle-archived.svg0000644000176200001440000000170714436206156017515 0ustar liggesusers lifecyclelifecyclearchivedarchived chk/man/figures/lifecycle-soft-deprecated.svg0000644000176200001440000000172614436206156021002 0ustar liggesuserslifecyclelifecyclesoft-deprecatedsoft-deprecated chk/man/figures/lifecycle-questioning.svg0000644000176200001440000000171414436206156020273 0ustar liggesuserslifecyclelifecyclequestioningquestioning chk/man/figures/lifecycle-stable.svg0000644000176200001440000000167414436206156017205 0ustar liggesuserslifecyclelifecyclestablestable chk/man/figures/lifecycle-experimental.svg0000644000176200001440000000171614436206156020425 0ustar liggesuserslifecyclelifecycleexperimentalexperimental chk/man/figures/lifecycle-deprecated.svg0000644000176200001440000000171214436206156020024 0ustar liggesuserslifecyclelifecycledeprecateddeprecated chk/man/figures/lifecycle-retired.svg0000644000176200001440000000170514436206156017364 0ustar liggesusers lifecyclelifecycleretiredretired chk/man/chk_deprecated.Rd0000644000176200001440000000747714436206156015034 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/deprecated.R \name{chk_deprecated} \alias{chk_deprecated} \alias{chk_dirs} \alias{chk_files} \alias{chk_has} \alias{chk_in} \alias{chk_no_missing} \alias{vld_no_missing} \alias{chk_off} \alias{chk_on} \alias{is_chk_on} \alias{chk_proportion} \alias{deparse_backtick} \title{Deprecated 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{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \description{ Deprecated \code{chk_()} functions. } \section{Functions}{ \itemize{ \item \code{chk_dirs()}: Check Directories Exist \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace with \verb{[chk_all](x, [chk_dir])} \item \code{chk_files()}: Check Files Exist \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace with \verb{[chk_all](x, [chk_file])} \item \code{chk_has()}: Check Has \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace by \code{\link[=chk_superset]{chk_superset()}} \item \code{chk_in()}: Check In \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace by \code{\link[=chk_subset]{chk_subset()}} \item \code{chk_no_missing()}: Check No Missing Values \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace with \code{\link[=chk_not_any_na]{chk_not_any_na()}} \item \code{vld_no_missing()}: Validate No Missing Values \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace with \code{\link[=vld_not_any_na]{vld_not_any_na()}} \item \code{chk_off()}: Turns checking off \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This approach is no longer recommended \item \code{chk_on()}: Turns checking on \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This approach is no longer recommended \item \code{is_chk_on()}: Tests checking on \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This approach is no longer recommended \item \code{chk_proportion()}: Check Proportion \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace by \verb{[chk_number](x); [chk_range](x)} \item \code{deparse_backtick()}: Deparse Backtick \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Replace with \code{\link[=deparse_backtick_chk]{deparse_backtick_chk()}} }} \seealso{ Other deprecated: \code{\link{chk_chr}()}, \code{\link{chk_dbl}()}, \code{\link{chk_wnum}()} } \concept{deprecated} \keyword{internal} chk/man/check_dirs.Rd0000644000176200001440000000156114436206156014171 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-dirs.R \name{check_dirs} \alias{check_dirs} \title{Check Directories Exist} \usage{ check_dirs(x, exists = TRUE, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{exists}{A flag specifying whether the files/directories must (or must not) exist.} \item{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. } \description{ Checks if all directories exist (or if exists = FALSE do not exist as directories or files). } \examples{ check_dirs(tempdir()) try(check_dirs(tempdir(), exists = FALSE)) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dim}()}, \code{\link{check_files}()}, \code{\link{check_key}()}, \code{\link{check_names}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_number.Rd0000644000176200001440000000223714436206156014211 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-number.R \name{chk_number} \alias{chk_number} \alias{vld_number} \title{Check Number} \usage{ chk_number(x, x_name = NULL) vld_number(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-missing numeric scalar using \code{is.numeric(x) && length(x) == 1L && !anyNA(x)} \strong{Pass}: \code{1}, \code{2L}, \code{log(10)}, \code{-Inf} \strong{Fail}: \code{"a"}, \code{1:3}, \code{NA_real_} } \section{Functions}{ \itemize{ \item \code{vld_number()}: Validate Number }} \examples{ # chk_number chk_number(1.1) try(chk_number(TRUE)) # vld_number vld_number(1.1) } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_date}()}, \code{\link{chk_scalar}()}, \code{\link{chk_string}()}, \code{\link{chk_tz}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_setequal.Rd0000644000176200001440000000253614436206156014546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-orderset.R, R/chk-setequal.R \name{vld_orderset} \alias{vld_orderset} \alias{chk_setequal} \alias{vld_setequal} \title{Check Set Equal} \usage{ vld_orderset(x, values) chk_setequal(x, values, x_name = NULL) vld_setequal(x, values) } \arguments{ \item{x}{The object to check.} \item{values}{A vector of the permitted values.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if equal set using \code{setequal(x, values)} } \section{Functions}{ \itemize{ \item \code{vld_orderset()}: Validate Set Ordered \item \code{vld_setequal()}: Validate Set Equal }} \examples{ # vld_orderset vld_orderset(1, 1) vld_orderset(1:2, 2:1) vld_orderset(1, 2:1) vld_orderset(1:2, 2) # chk_setequal chk_setequal(1:2, 2:1) try(chk_setequal(1, 1:2)) # vld_setequal vld_setequal(1, 1) vld_setequal(1:2, 2:1) vld_setequal(1, 2:1) vld_setequal(1:2, 2) } \seealso{ Other chk_set: \code{\link{chk_join}()}, \code{\link{chk_not_subset}()}, \code{\link{chk_orderset}()}, \code{\link{chk_superset}()}, \code{\link{vld_not_subset}()} } \concept{chk_set} chk/man/chk_date_time.Rd0000644000176200001440000000342414436206156014653 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-datetime.R \name{chk_date_time} \alias{chk_date_time} \alias{chk_datetime} \alias{vld_date_time} \alias{vld_datetime} \title{Check Date Time} \usage{ chk_date_time(x, x_name = NULL) chk_datetime(x, x_name = NULL) vld_date_time(x) vld_datetime(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-missing POSIXct scalar using \code{inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)} } \section{Functions}{ \itemize{ \item \code{chk_datetime()}: Check Date Time (Deprecated) \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} \item \code{vld_date_time()}: Validate Date Time \item \code{vld_datetime()}: Validate Date Time (Deprecated) \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} }} \examples{ # chk_date_time chk_date_time(as.POSIXct("2001-01-02")) try(chk_date_time(1)) # vld_date_time vld_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())) } \seealso{ Other chk_scalars: \code{\link{chk_date}()}, \code{\link{chk_number}()}, \code{\link{chk_scalar}()}, \code{\link{chk_string}()}, \code{\link{chk_tz}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_character.Rd0000644000176200001440000000237114436206156014654 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-character.R \name{chk_character} \alias{chk_character} \alias{vld_character} \title{Check Character} \usage{ chk_character(x, x_name = NULL) vld_character(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if character using \code{is.character(x)} } \section{Functions}{ \itemize{ \item \code{vld_character()}: Validate Character }} \examples{ # chk_character chk_character("1") try(chk_character(1)) # vld_character vld_character("1") vld_character(matrix("a")) vld_character(character(0)) vld_character(NA_character_) vld_character(1) vld_character(TRUE) vld_character(factor("text")) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_match.Rd0000644000176200001440000000250014436206156014006 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-match.R \name{chk_match} \alias{chk_match} \alias{vld_match} \title{Check Matches} \usage{ chk_match(x, regexp = ".+", x_name = NULL) vld_match(x, regexp = ".+") } \arguments{ \item{x}{The object to check.} \item{regexp}{A string of a regular expression.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all values match regular expression using \code{all(grepl(regexp, x[!is.na(x)]))} } \section{Functions}{ \itemize{ \item \code{vld_match()}: Validate Matches }} \examples{ # chk_match chk_match("1") try(chk_match("1", regexp = "2")) # vld_match vld_match("1") vld_match("a", regexp = "a") vld_match("") vld_match("1", regexp = "2") vld_match(NA_character_, regexp = ".*") } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_gt.Rd0000644000176200001440000000221314436206156013325 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-gt.R \name{chk_gt} \alias{chk_gt} \alias{vld_gt} \title{Check Greater Than} \usage{ chk_gt(x, value = 0, x_name = NULL) vld_gt(x, value = 0) } \arguments{ \item{x}{The object to check.} \item{value}{A non-missing scalar of a value.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all non-missing values are greater than value using \code{all(x[!is.na(x)] > value)} } \section{Functions}{ \itemize{ \item \code{vld_gt()}: Validate Greater Than }} \examples{ # chk_gt chk_gt(0.1) try(chk_gt(c(0.1, -0.2))) # vld_gt vld_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") } \seealso{ Other chk_ranges: \code{\link{chk_gte}()}, \code{\link{chk_lte}()}, \code{\link{chk_lt}()}, \code{\link{chk_range}()} } \concept{chk_ranges} chk/man/chk_count.Rd0000644000176200001440000000216514436206156014051 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-count.R \name{chk_count} \alias{chk_count} \alias{vld_count} \title{Check Count} \usage{ chk_count(x, x_name = NULL) vld_count(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-negative whole number using \code{vld_whole_number(x) && x >= 0} } \section{Functions}{ \itemize{ \item \code{vld_count()}: Validate Count }} \examples{ # chk_count chk_count(1) try(chk_count(1.5)) # vld_count vld_count(1) vld_count(0L) vld_count(-1) vld_count(0.5) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_valid_name.Rd0000644000176200001440000000227214436206156015017 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-valid-name.R \name{chk_valid_name} \alias{chk_valid_name} \alias{vld_valid_name} \title{Check Valid Name} \usage{ chk_valid_name(x, x_name = NULL) vld_valid_name(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if valid name using \code{identical(make.names(x[!is.na(x)]), as.character(x[!is.na(x)]))} } \section{Functions}{ \itemize{ \item \code{vld_valid_name()}: Validate Valid Name }} \examples{ # chk_valid_name chk_valid_name("text") try(chk_valid_name(".1")) # vld_valid_name vld_valid_name(".1") } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_not_missing}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()} } \concept{chk_misc} chk/man/chk_lt.Rd0000644000176200001440000000220514436206156013333 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-lt.R \name{chk_lt} \alias{chk_lt} \alias{vld_lt} \title{Check Less Than} \usage{ chk_lt(x, value = 0, x_name = NULL) vld_lt(x, value = 0) } \arguments{ \item{x}{The object to check.} \item{value}{A non-missing scalar of a value.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all non-missing values are less than value using \code{all(x[!is.na(x)] < value)} } \section{Functions}{ \itemize{ \item \code{vld_lt()}: Validate Less Than }} \examples{ # chk_lt chk_lt(-0.1) try(chk_lt(c(-0.1, 0.2))) # vld_lt vld_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") } \seealso{ Other chk_ranges: \code{\link{chk_gte}()}, \code{\link{chk_gt}()}, \code{\link{chk_lte}()}, \code{\link{chk_range}()} } \concept{chk_ranges} chk/man/check_dim.Rd0000644000176200001440000000206614436206156014002 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-dim.R \name{check_dim} \alias{check_dim} \title{Check Dimension} \usage{ check_dim(x, dim = length, values = numeric(0), x_name = NULL, dim_name = NULL) } \arguments{ \item{x}{The object to check.} \item{dim}{A function returning a non-negative whole number of the dimension.} \item{values}{A flag or a whole numeric vector of the value, value range or possible values.} \item{x_name}{A string of the name of object x or NULL.} \item{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. } \description{ Checks dimension of an object. } \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))) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dirs}()}, \code{\link{check_files}()}, \code{\link{check_key}()}, \code{\link{check_names}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_equal.Rd0000644000176200001440000000230214436206156014021 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-equal.R \name{chk_equal} \alias{chk_equal} \alias{vld_equal} \title{Check Equal} \usage{ chk_equal(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL) vld_equal(x, y, tolerance = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{The object to check.} \item{y}{An object to check against.} \item{tolerance}{A non-negative numeric scalar.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is equal (identical within tolerance) to y using \code{vld_true(all.equal(x, y, tolerance))} } \section{Functions}{ \itemize{ \item \code{vld_equal()}: Validate Equal }} \examples{ # chk_equal chk_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) } \seealso{ Other chk_equals: \code{\link{chk_equivalent}()}, \code{\link{chk_identical}()} } \concept{chk_equals} chk/man/check_data.Rd0000644000176200001440000000261514436206156014142 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-data.R \name{check_data} \alias{check_data} \title{Check Data} \usage{ check_data( x, values = NULL, exclusive = FALSE, order = FALSE, nrow = numeric(0), key = character(0), x_name = NULL ) } \arguments{ \item{x}{The object to check.} \item{values}{A uniquely named list of atomic vectors of the column values.} \item{exclusive}{A flag specifying whether x must only include columns named in values.} \item{order}{A flag specifying whether the order of columns in x must match names in values.} \item{nrow}{A flag or a whole numeric vector of the value, value range or possible values.} \item{key}{A character vector of the columns that represent a unique key.} \item{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. } \description{ Checks column names, values, number of rows and key for a data.frame. } \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)) } \seealso{ Other check: \code{\link{check_dim}()}, \code{\link{check_dirs}()}, \code{\link{check_files}()}, \code{\link{check_key}()}, \code{\link{check_names}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_numeric.Rd0000644000176200001440000000254614436206156014366 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-numeric.R \name{chk_numeric} \alias{chk_numeric} \alias{vld_numeric} \title{Check Numeric} \usage{ chk_numeric(x, x_name = NULL) vld_numeric(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if numeric using \code{is.numeric(x)} \strong{Pass}: \code{1}, \code{1:2}, \code{NA_real_}, \code{integer(0)}, \code{matrix(1:3)}. \strong{Fail}: \code{TRUE}, \code{"1"}, \code{NA}, \code{NULL}. } \section{Functions}{ \itemize{ \item \code{vld_numeric()}: Validate Numeric }} \examples{ # chk_numeric chk_numeric(1) try(chk_numeric("1")) # vld_numeric vld_numeric(1) vld_numeric(1:2) vld_numeric(NA_real_) vld_numeric(integer(0)) vld_numeric("1") vld_numeric(TRUE) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_true.Rd0000644000176200001440000000173414436206156013701 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-true.R \name{chk_true} \alias{chk_true} \alias{vld_true} \title{Check TRUE} \usage{ chk_true(x, x_name = NULL) vld_true(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if TRUE using \code{is.logical(x) && length(x) == 1L && !anyNA(x) && x} } \section{Functions}{ \itemize{ \item \code{vld_true()}: Validate TRUE }} \examples{ # chk_true chk_true(TRUE) try(chk_true(1)) # vld_true vld_true(TRUE) vld_true(FALSE) vld_true(NA) vld_true(0) vld_true(c(TRUE, TRUE)) } \seealso{ Other chk_logical: \code{\link{chk_false}()}, \code{\link{chk_flag}()}, \code{\link{chk_lgl}()} } \concept{chk_logical} chk/man/chk_data.Rd0000644000176200001440000000222214436206156013624 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-data.R \name{chk_data} \alias{chk_data} \alias{vld_data} \title{Check Data} \usage{ chk_data(x, x_name = NULL) vld_data(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks data.frame using \code{inherits(x, "data.frame")} } \section{Functions}{ \itemize{ \item \code{vld_data()}: Validate Data }} \examples{ # chk_data chk_data(data.frame(x = 1)) try(chk_data(1)) # vld_data vld_data(data.frame()) vld_data(data.frame(x = 1)) vld_data(c(x = 1)) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_join.Rd0000644000176200001440000000270014436206156013653 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-join.R \name{chk_join} \alias{chk_join} \alias{vld_join} \title{Check Join} \usage{ chk_join(x, y, by, x_name = NULL) vld_join(x, y, by) } \arguments{ \item{x}{The object to check.} \item{y}{A data.frame with columns in by.} \item{by}{A character vector specifying the column names to join x and y on. If named the names are the corresponding columns in x.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if all rows in x match at least one in y. } \section{Functions}{ \itemize{ \item \code{vld_join()}: Validate Join }} \examples{ # chk_join chk_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_join vld_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")) } \seealso{ Other chk_set: \code{\link{chk_not_subset}()}, \code{\link{chk_orderset}()}, \code{\link{chk_superset}()}, \code{\link{vld_not_subset}()}, \code{\link{vld_orderset}()} } \concept{chk_set} chk/man/aaa.Rd0000644000176200001440000000070314436206156012612 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/aaa.R \name{aaa} \alias{aaa} \title{Workaround: Avoid backtraces in examples} \description{ This example will run first and set the option for the process that builds the 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") } \keyword{internal} chk/man/chk_s4_class.Rd0000644000176200001440000000257214436206156014436 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-s4-class.R \name{chk_s4_class} \alias{chk_s4_class} \alias{vld_s4_class} \title{Check Inherits from S4 Class} \usage{ chk_s4_class(x, class, x_name = NULL) vld_s4_class(x, class) } \arguments{ \item{x}{The object to check.} \item{class}{A string specifying the class.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks inherits from S4 class using \code{isS4(x) && methods::is(x, class)} } \section{Functions}{ \itemize{ \item \code{vld_s4_class()}: Validate Inherits from S4 Class }} \examples{ # chk_s4_class try(chk_s4_class(1, "numeric")) chk_s4_class(getClass("MethodDefinition"), "classRepresentation") # vld_s4_class vld_s4_class(numeric(0), "numeric") vld_s4_class(getClass("MethodDefinition"), "classRepresentation") } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_date.Rd0000644000176200001440000000207014436206156013631 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-date.R \name{chk_date} \alias{chk_date} \alias{vld_date} \title{Check Date} \usage{ chk_date(x, x_name = NULL) vld_date(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks non-missing Date scalar using \code{inherits(x, "Date") && length(x) == 1L && !anyNA(x)} } \section{Functions}{ \itemize{ \item \code{vld_date()}: Validate Date }} \examples{ # chk_date chk_date(Sys.Date()) try(chk_date(1)) # vld_date vld_date(Sys.Date()) vld_date(Sys.time()) vld_date(1) } \seealso{ Other chk_scalars: \code{\link{chk_date_time}()}, \code{\link{chk_number}()}, \code{\link{chk_scalar}()}, \code{\link{chk_string}()}, \code{\link{chk_tz}()}, \code{\link{chk_whole_number}()} } \concept{chk_scalars} chk/man/chk_integer.Rd0000644000176200001440000000227014436206156014353 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-integer.R \name{chk_integer} \alias{chk_integer} \alias{vld_integer} \title{Check Integer} \usage{ chk_integer(x, x_name = NULL) vld_integer(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if integer using \code{is.integer(x)} } \section{Functions}{ \itemize{ \item \code{vld_integer()}: Validate Integer }} \examples{ # chk_integer chk_integer(1L) try(chk_integer(1)) # vld_integer vld_integer(1L) vld_integer(matrix(1:4, nrow = 2L)) vld_integer(integer(0)) vld_integer(NA_integer_) vld_integer(1) vld_integer(TRUE) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_environment}()}, \code{\link{chk_factor}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_false.Rd0000644000176200001440000000176114436206156014014 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-false.R \name{chk_false} \alias{chk_false} \alias{vld_false} \title{Check FALSE} \usage{ chk_false(x, x_name = NULL) vld_false(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Check if FALSE using \code{is.logical(x) && length(x) == 1L && !anyNA(x) && !x} } \section{Functions}{ \itemize{ \item \code{vld_false()}: Validate FALSE }} \examples{ # chk_false chk_false(FALSE) try(chk_false(0)) # vld_false vld_false(TRUE) vld_false(FALSE) vld_false(NA) vld_false(0) vld_false(c(FALSE, FALSE)) } \seealso{ Other chk_logical: \code{\link{chk_flag}()}, \code{\link{chk_lgl}()}, \code{\link{chk_true}()} } \concept{chk_logical} chk/man/chk_vector.Rd0000644000176200001440000000246114436206156014222 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-vector.R \name{chk_vector} \alias{chk_vector} \alias{vld_vector} \title{Check Vector} \usage{ chk_vector(x, x_name = NULL) vld_vector(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is a vector using \code{(is.atomic(x) && !is.matrix(x) && !is.array(x)) || is.list(x)} } \details{ \code{is.vector(x)} is not reliable because it returns TRUE only if the object is a vector with no attributes apart from names. } \section{Functions}{ \itemize{ \item \code{vld_vector()}: Validate Vector }} \examples{ # chk_vector chk_vector(1) chk_vector(list()) try(chk_vector(matrix(1))) # vld_vector vld_vector(1) } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s3_class}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/check_names.Rd0000644000176200001440000000211214436206156014324 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-names.R \name{check_names} \alias{check_names} \title{Check Names} \usage{ check_names( x, names = character(0), exclusive = FALSE, order = FALSE, x_name = NULL ) } \arguments{ \item{x}{The object to check.} \item{names}{A character vector of the required names.} \item{exclusive}{A flag specifying whether x must only contain the required names.} \item{order}{A flag specifying whether the order of the required names in x must match the order in names.} \item{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. } \description{ Checks the names of an object. } \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)) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dim}()}, \code{\link{check_dirs}()}, \code{\link{check_files}()}, \code{\link{check_key}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_flag.Rd0000644000176200001440000000210014436206156013617 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-flag.R \name{chk_flag} \alias{chk_flag} \alias{vld_flag} \title{Check Flag} \usage{ chk_flag(x, x_name = NULL) vld_flag(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if non-missing logical scalar using \code{is.logical(x) && length(x) == 1L && !anyNA(x)} \strong{Pass}: \code{TRUE}, \code{FALSE}. \strong{Fail}: \code{logical(0)}, \code{c(TRUE, TRUE)}, \code{"TRUE"}, \code{1}, \code{NA}. } \section{Functions}{ \itemize{ \item \code{vld_flag()}: Validate Flag }} \examples{ # chk_flag chk_flag(TRUE) try(vld_flag(1)) # vld_flag vld_flag(TRUE) vld_flag(1) } \seealso{ Other chk_logical: \code{\link{chk_false}()}, \code{\link{chk_lgl}()}, \code{\link{chk_true}()} } \concept{chk_logical} chk/man/check_files.Rd0000644000176200001440000000164014436206156014330 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/check-files.R \name{check_files} \alias{check_files} \title{Check Files Exist} \usage{ check_files(x, exists = TRUE, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{exists}{A flag specifying whether the files/directories must (or must not) exist.} \item{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. } \description{ Checks if all files exist (or if exists = FALSE do not exist as files or directories). } \examples{ check_files(tempfile("unlikely-that-exists-chk"), exists = FALSE) try(check_files(tempfile("unlikely-that-exists-chk"))) } \seealso{ Other check: \code{\link{check_data}()}, \code{\link{check_dim}()}, \code{\link{check_dirs}()}, \code{\link{check_key}()}, \code{\link{check_names}()}, \code{\link{check_values}()} } \concept{check} chk/man/chk_not_missing.Rd0000644000176200001440000000247514436206156015256 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-missing.R \name{chk_not_missing} \alias{chk_not_missing} \alias{vld_not_missing} \title{Check Not Missing Argument} \usage{ chk_not_missing(x, x_name = "`x`") vld_not_missing(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks argument not missing using \code{!missing(x)} } \details{ Currently only checks if value is available (as opposed to whether it was specified). } \section{Functions}{ \itemize{ \item \code{vld_not_missing()}: Validate Not Missing Argument }} \examples{ # chk_not_missing fun <- function(x) { chk_not_missing(x) } fun(1) try(fun()) # vld_not_missing fun <- function(x) { vld_not_missing(x) } fun() fun(1) } \seealso{ Other chk_misc: \code{\link{chk_length}()}, \code{\link{chk_match}()}, \code{\link{chk_missing}()}, \code{\link{chk_named}()}, \code{\link{chk_not_any_na}()}, \code{\link{chk_not_empty}()}, \code{\link{chk_sorted}()}, \code{\link{chk_unique}()}, \code{\link{chk_valid_name}()} } \concept{chk_misc} chk/man/chk_identical.Rd0000644000176200001440000000202614436206156014651 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-identical.R \name{chk_identical} \alias{chk_identical} \alias{vld_identical} \title{Check Identical} \usage{ chk_identical(x, y, x_name = NULL) vld_identical(x, y) } \arguments{ \item{x}{The object to check.} \item{y}{An object to check against.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if is identical to y using \code{identical(x, y)} } \section{Functions}{ \itemize{ \item \code{vld_identical()}: Validate Identical }} \examples{ # chk_identical chk_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) } \seealso{ Other chk_equals: \code{\link{chk_equal}()}, \code{\link{chk_equivalent}()} } \concept{chk_equals} chk/man/chk_environment.Rd0000644000176200001440000000233114436206156015260 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-environment.R \name{chk_environment} \alias{chk_environment} \alias{vld_environment} \title{Check Environment} \usage{ chk_environment(x, x_name = NULL) vld_environment(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if environment using \code{is.environment(x)} } \section{Functions}{ \itemize{ \item \code{vld_environment()}: Validate Environment }} \examples{ # chk_environment chk_environment(.GlobalEnv) try(chk_environment(1)) # vld_environment vld_environment(1) vld_environment(list(1)) vld_environment(.GlobalEnv) vld_environment(environment()) } \seealso{ Other chk_typeof: \code{\link{chk_character_or_factor}()}, \code{\link{chk_character}()}, \code{\link{chk_count}()}, \code{\link{chk_double}()}, \code{\link{chk_factor}()}, \code{\link{chk_integer}()}, \code{\link{chk_list}()}, \code{\link{chk_logical}()} } \concept{chk_typeof} chk/man/chk_not_subset.Rd0000644000176200001440000000172014436206156015102 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-not-subset.R \name{chk_not_subset} \alias{chk_not_subset} \title{Check Not Subset} \usage{ chk_not_subset(x, values, x_name = NULL) } \arguments{ \item{x}{The object to check.} \item{values}{A vector of the permitted values.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if not all values in values using \code{!any(x \%in\% values) || !length(x)} } \examples{ # chk_not_subset chk_not_subset(11, 1:10) try(chk_not_subset(1, 1:10)) } \seealso{ Other chk_set: \code{\link{chk_join}()}, \code{\link{chk_orderset}()}, \code{\link{chk_superset}()}, \code{\link{vld_not_subset}()}, \code{\link{vld_orderset}()} } \concept{chk_set} chk/man/chk_s3_class.Rd0000644000176200001440000000254614436206156014436 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-s3-class.R \name{chk_s3_class} \alias{chk_s3_class} \alias{vld_s3_class} \title{Check Type} \usage{ chk_s3_class(x, class, x_name = NULL) vld_s3_class(x, class) } \arguments{ \item{x}{The object to check.} \item{class}{A string specifying the class.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks inherits from S3 class using \code{!isS4(x) && inherits(x, class)} } \section{Functions}{ \itemize{ \item \code{vld_s3_class()}: Validate Inherits from S3 Class }} \examples{ # chk_s3_class chk_s3_class(1, "numeric") try(chk_s3_class(getClass("MethodDefinition"), "classRepresentation")) # vld_s3_class vld_s3_class(numeric(0), "numeric") vld_s3_class(getClass("MethodDefinition"), "classRepresentation") } \seealso{ Other chk_is: \code{\link{chk_array}()}, \code{\link{chk_atomic}()}, \code{\link{chk_data}()}, \code{\link{chk_function}()}, \code{\link{chk_is}()}, \code{\link{chk_matrix}()}, \code{\link{chk_numeric}()}, \code{\link{chk_s4_class}()}, \code{\link{chk_vector}()}, \code{\link{chk_whole_numeric}()} } \concept{chk_is} chk/man/chk_lgl.Rd0000644000176200001440000000172714436206156013502 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-lgl.R \name{chk_lgl} \alias{chk_lgl} \alias{vld_lgl} \title{Check Logical Scalar} \usage{ chk_lgl(x, x_name = NULL) vld_lgl(x) } \arguments{ \item{x}{The object to check.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks if logical scalar using \code{is.logical(x) && length(x) == 1L} } \section{Functions}{ \itemize{ \item \code{vld_lgl()}: Validate Logical Scalar }} \examples{ # chk_lgl chk_lgl(NA) try(chk_lgl(1)) # vld_lgl vld_lgl(TRUE) vld_lgl(FALSE) vld_lgl(NA) vld_lgl(1) vld_lgl(c(TRUE, TRUE)) } \seealso{ Other chk_logical: \code{\link{chk_false}()}, \code{\link{chk_flag}()}, \code{\link{chk_true}()} } \concept{chk_logical} chk/man/chk_ext.Rd0000644000176200001440000000222314436206156013514 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-ext.R \name{chk_ext} \alias{chk_ext} \alias{vld_ext} \title{Check File Extension} \usage{ chk_ext(x, ext, x_name = NULL) vld_ext(x, ext) } \arguments{ \item{x}{The object to check.} \item{ext}{A character vector of the permitted file extensions (without the .).} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks extension using \code{vld_string(x) && vld_subset(tools::file_ext(x), ext)} The user may want to use \code{\link[=toupper]{toupper()}} or \code{\link[=tolower]{tolower()}} to ensure the case matches. } \section{Functions}{ \itemize{ \item \code{vld_ext()}: Validate File Extension }} \examples{ # chk_ext try(chk_ext("file1.pdf", "png")) # vld_ext vld_ext("oeu.pdf", "pdf") vld_ext(toupper("oeu.pdf"), "PDF") } \seealso{ Other chk_files: \code{\link{chk_dir}()}, \code{\link{chk_file}()} } \concept{chk_files} chk/man/chk_all_equal.Rd0000644000176200001440000000242214436206156014654 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/chk-all-equal.R \name{chk_all_equal} \alias{chk_all_equal} \alias{vld_all_equal} \title{Check All Equal} \usage{ chk_all_equal(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL) vld_all_equal(x, tolerance = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{The object to check.} \item{tolerance}{A non-negative numeric scalar.} \item{x_name}{A string of the name of object x or NULL.} } \value{ The \code{chk_} function throws an informative error if the test fails or returns the original object if successful so it can used in pipes. The \code{vld_} function returns a flag indicating whether the test was met. } \description{ Checks all elements in x equal using \code{length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance))} } \section{Functions}{ \itemize{ \item \code{vld_all_equal()}: Validate All Equal }} \examples{ # chk_all_equal chk_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_equal vld_all_equal(c(1, 1L)) } \seealso{ Other chk_alls: \code{\link{chk_all_equivalent}()}, \code{\link{chk_all_identical}()}, \code{\link{chk_all}()} } \concept{chk_alls} chk/DESCRIPTION0000644000176200001440000000357614507671602012550 0ustar liggesusersPackage: chk Title: Check User-Supplied Function Arguments Version: 0.9.1 Authors@R: c( person("Joe", "Thorley", , "joe@poissonconsulting.ca", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7683-4592")), person("Kirill", "Müller", role = "aut", comment = c(ORCID = "0000-0002-1416-3412")), person("Ayla", "Pearson", role = "aut", comment = c(ORCID = "0000-0001-7388-1222")), person("Nadine", "Hussein", , "nadine@poissonconsulting.ca", role = "ctb", comment = c(ORCID = "0000-0003-4470-8361")), person("Evan", "Amies-Galonski", , "evan@poissonconsulting.ca", role = "ctb", comment = c(ORCID = "0000-0003-1096-2089")), person("Poisson Consulting", role = c("cph", "fnd")) ) 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://poissonconsulting.github.io/chk/, https://github.com/poissonconsulting/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/testthat/edition: 3 Encoding: UTF-8 Language: en-US RoxygenNote: 7.2.3 NeedsCompilation: no Packaged: 2023-10-05 21:37:43 UTC; joe Author: Joe Thorley [aut, cre] (), Kirill Müller [aut] (), Ayla Pearson [aut] (), Nadine Hussein [ctb] (), Evan Amies-Galonski [ctb] (), Poisson Consulting [cph, fnd] Maintainer: Joe Thorley Repository: CRAN Date/Publication: 2023-10-06 02:40:02 UTC chk/build/0000755000176200001440000000000014507626246012132 5ustar liggesuserschk/build/vignette.rds0000644000176200001440000000034714507626246014475 0ustar liggesusersu0ECyD?? _Apƨ @/K;}l@8:` /e*\Hݾcil_9i8Mqx4icr^7l\.D*(aZ#3#)!tЎYAWX(b8}*U諫 P [ް %iU"pf ?[.]" ) expect_chk_error( check_values(ordered(c(1, 3), levels = 1:3), ordered(c(1, 2), levels = 1:3)), "^`ordered[(]c[(]1, 3[)], levels = 1:3[)]` must have values between '1' and '2'[.]$" ) expect_chk_error( check_values(factor(1:2), factor(1:2, levels = 2:1)), "^`levels[(]factor[(]1:2[)][)]` must have [(]the first occurence of[)] each of the following elements in the following order: '2', '1'[.]$" ) expect_chk_error( check_values(ordered(1:2), ordered(1:2, levels = 2:1)), "^`levels[(]ordered[(]1:2[)][)]` must have [(]the first occurence of[)] each of the following elements in the following order: '2', '1'[.]$" ) }) chk/tests/testthat/test-check-names.R0000644000176200001440000000266114436206156017313 0ustar liggesuserstest_that("check_names", { expect_identical(check_names(c(x = 1)), c(x = 1)) expect_invisible(check_names(c(x = 1))) expect_identical(check_names(c(x = 1), "x"), check_names(c(x = 1), "x")) expect_identical( check_names(c(x = 1, y = 2), "x"), check_names(c(x = 1, y = 2), "x") ) expect_identical( check_names(c(x = 1, y = 2), c("y", "x")), check_names(c(x = 1, y = 2), c("y", "x")) ) }) test_that("check_names fails", { expect_chk_error( check_names(character(0)), "^`character[(]0[)]` must be named[.]$" ) x <- structure(list(), .Names = character(0)) x <- structure(list(), .Names = character(0)) expect_chk_error( check_names(c(x = 1), exclusive = TRUE), "^`c[(]x = 1[)]` must not have any elements[.]$" ) expect_chk_error( check_names(x, "x"), "^`names[(]x[)]` must include 'x'[.]$" ) expect_chk_error( check_names(c(x = 1), c("x", "y")), "`names[(]c[(]x = 1[)][)]` must include 'y'[.]$" ) expect_chk_error( check_names(c(x = 1, z = 2), "x", exclusive = TRUE), "^`names[(]c[(]x = 1, z = 2[)][)]` must not include 'z'[.]$" ) expect_chk_error( check_names(c(x = 1, y = 2), c("y", "x"), order = TRUE), "`names[(]c[(]x = 1, y = 2[)][)]` must include 'y' and 'x' in that order[.]$" ) expect_chk_error( check_names(c(x = 1, y = 2), c("y", "x"), order = TRUE, x_name = "b"), "`names[(]b[)]` must include 'y' and 'x' in that order[.]$" ) }) chk/tests/testthat/test-chk-unique.R0000644000176200001440000000457714436206156017216 0ustar liggesuserstest_that("vld_unique", { expect_true(vld_unique(integer(0))) expect_true(vld_unique(NA)) expect_true(vld_unique(1)) expect_true(vld_unique(c(1, 2))) expect_true(vld_unique(c(1, NA))) expect_false(vld_unique(c(NA, NA))) expect_true(vld_unique(c(NA, NA), incomparables = NA)) expect_true(vld_unique(c(NA, NA, 1), incomparables = NA)) expect_false(vld_unique(c(1, 1))) expect_false(vld_unique(c(1, 2, 1))) }) test_that("chk_unique", { expect_identical(chk_unique(1), 1) expect_invisible(chk_unique(1)) expect_chk_error(chk_unique(c(1, 1)), "^`c[(]1, 1[)]` must be unique[.]$") expect_chk_error(chk_unique(c(1, 1), x_name = "unicorn"), "^Unicorn must be unique[.]$") }) test_that("vld_unique data frame", { data <- data.frame(x = 1:2) expect_true(vld_unique(data)) expect_true(vld_unique(data, incomparables = NA)) data <- data.frame(x = c(1, 1)) expect_false(vld_unique(data)) expect_false(vld_unique(data, incomparables = NA)) data <- data.frame(y = c(NA, NA)) expect_true(vld_unique(data, incomparables = NA)) data <- data.frame(x = 1:2, y = c(NA, NA)) expect_true(vld_unique(data)) expect_true(vld_unique(data, incomparables = NA)) data <- data.frame(x = c(1, 1), y = c(2, 2)) expect_true(vld_unique(data, incomparables = 2)) data <- data.frame(x = c(1, 1), y = c(NA, NA)) expect_true(vld_unique(data, incomparables = NA)) }) test_that("chk_unique data frame", { data <- data.frame(x = 1:2) expect_identical(chk_unique(data), data) expect_invisible(chk_unique(data)) data <- data.frame(y = c(NA, NA)) expect_chk_error(chk_unique(data), "^`data` must be unique[.]$") data <- data.frame(x = 1:2, y = c(NA, NA)) data <- data.frame(x = c(1, 1), y = c(2, 2)) expect_chk_error(chk_unique(data), "^`data` must be unique[.]$") data <- data.frame(x = c(1, 1), y = c(NA, NA)) expect_chk_error(chk_unique(data), "^`data` must be unique[.]$") }) test_that("vld_named", { expect_false(vld_named(list())) expect_false(vld_named(list(1))) expect_true(vld_named(list(x = 1))) expect_true(vld_named(list(x = 1)[-1])) expect_true(vld_named(c(x = 1))) expect_true(vld_named(c(x = 1)[-1])) }) test_that("chk_named", { expect_identical(chk_named(c(x = 1)), c(x = 1)) expect_invisible(chk_named(c(x = 1))) expect_chk_error(chk_named(1), "^`1` must be named[.]$") expect_chk_error(chk_named(1, x_name = "new born"), "^New born must be named[.]$") }) chk/tests/testthat/test-chk-missing.R0000644000176200001440000000232314436206156017344 0ustar liggesuserstest_that("vld_missing", { expect_true(vld_missing()) expect_false(vld_missing(1)) }) test_that("vld_missing in function", { fun <- function(x) vld_missing(x) expect_true(fun()) expect_false(fun(1)) }) test_that("vld_missing in function default", { fun <- function(x = 1) vld_missing(x) # this might be expected to be true if testing whether specified expect_false(fun()) expect_false(fun(1)) }) test_that("chk_missing", { expect_null(chk_missing()) expect_invisible(chk_missing()) expect_chk_error(chk_missing(1), "^`1` must be missing\\.$") expect_chk_error(chk_missing(1, x_name = "`y`"), "^`y` must be missing\\.$") }) test_that("chk_missing in function", { fun <- function(x) chk_missing(x) expect_null(fun()) expect_invisible(fun()) expect_chk_error(fun(1), "^`x` must be missing\\.$") }) test_that("chk_missing in function default", { fun <- function(x = 1) chk_missing(x) # this might be expected to be an error if testing whether specified expect_chk_error(fun(), "^`x` must be missing\\.$") # this might be expected to be an error if testing whether specified expect_chk_error(fun(NULL), "^`x` must be missing\\.$") expect_chk_error(fun(1), "^`x` must be missing\\.$") }) chk/tests/testthat/test-chk-not-empty.R0000644000176200001440000000140614436206156017630 0ustar liggesuserstest_that("vld_not_empty", { expect_true(vld_not_empty(1)) expect_true(vld_not_empty(matrix(1:3))) expect_true(vld_not_empty(NA)) expect_true(vld_not_empty(list(1))) expect_true(vld_not_empty(matrix(1))) expect_true(vld_not_empty(data.frame(x = 1))) expect_false(vld_not_empty(NULL)) expect_false(vld_not_empty(integer(0))) expect_false(vld_not_empty(list())) expect_false(vld_not_empty(matrix(integer(0)))) expect_false(vld_not_empty(data.frame())) }) test_that("chk_not_empty", { expect_identical(chk_not_empty(1), 1) expect_invisible(chk_not_empty(1)) expect_chk_error(chk_not_empty(NULL), "^`NULL` must not be empty [(]zero length[)][.]$") expect_chk_error(chk_not_empty(NULL, x_name = 1), "^1 must not be empty [(]zero length[)][.]$") }) chk/tests/testthat/test-chk-string.R0000644000176200001440000000235014436206156017201 0ustar liggesuserstest_that("vld_string", { expect_false(vld_string(character(0))) expect_false(vld_string(NA_character_)) expect_true(vld_string("")) expect_true(vld_string("a")) expect_false(vld_string(c("a", "b"))) }) test_that("chk_string", { expect_identical(chk_string(""), "") expect_invisible(chk_string("")) expect_chk_error(chk_string(1), "^`1` must be a string [(]non-missing character scalar[)][.]$") expect_chk_error(chk_string(1, x_name = "''"), "^'' must be a string [(]non-missing character scalar[)][.]$") }) test_that("vld_match", { expect_true(vld_match(character(0))) expect_true(vld_match(1)) expect_true(vld_match("a")) expect_true(vld_match(NA)) expect_true(vld_match(c(NA, "b"), "b")) expect_false(vld_match("")) expect_true(vld_match(c("a", "b"))) }) test_that("chk_match", { expect_identical(chk_match("1"), "1") expect_invisible(chk_match("1")) expect_chk_error(chk_match(""), "^`\"\"` must match regular expression '.+'[.]$") expect_chk_error( chk_match(c("a", "b"), "b"), "`c[(]\"a\", \"b\"[)]` must have values matching regular expression 'b'[.]$" ) expect_chk_error( chk_match(c("a", "b"), "b"), "`c[(]\"a\", \"b\"[)]` must have values matching regular expression 'b'[.]$" ) }) chk/tests/testthat/test-chk-count.R0000644000176200001440000000116114436206156017022 0ustar liggesuserstest_that("vld_count", { expect_true(vld_count(1)) expect_true(vld_count(0)) expect_true(vld_count(100L)) expect_false(vld_count(0.5)) expect_false(vld_count(-1L)) expect_false(vld_count(NA_integer_)) expect_false(vld_count(integer(0))) }) test_that("chk_count", { expect_identical(chk_count(1), 1) expect_invisible(chk_count(1)) expect_chk_error(chk_count(1.1), "^`1.1` must be a count [(]non-negative non-missing integer scalar or double equivalent[)][.]$") expect_chk_error(chk_count(1.1, x_name = 1L), "^1 must be a count [(]non-negative non-missing integer scalar or double equivalent[)][.]$") }) chk/tests/testthat/test-chk-not-missing.R0000644000176200001440000000207414436206156020145 0ustar liggesuserstest_that("vld_not_missing", { expect_false(vld_not_missing()) expect_true(vld_not_missing(1)) }) test_that("vld_not_missing in function", { fun <- function(x) vld_not_missing(x) expect_false(fun()) expect_true(fun(1)) }) test_that("vld_not_missing in function default", { fun <- function(x = 1) vld_not_missing(x) # this might be expected to be false if testing whether specified expect_true(fun()) expect_true(fun(1)) }) test_that("chk_not_missing", { expect_identical(chk_not_missing(1), 1) expect_invisible(chk_not_missing(1)) expect_chk_error(chk_not_missing(), "^`x` must not be missing\\.$") expect_chk_error(chk_not_missing(x_name = "`y`"), "^`y` must not be missing\\.$") }) test_that("chk_not_missing in function", { fun <- function(x) chk_not_missing(x) expect_chk_error(fun(), "^`x` must not be missing\\.$") expect_identical(fun(1), 1) }) test_that("chk_not_missing in function default", { fun <- function(x = 1) chk_not_missing(x) expect_identical(fun(NULL), NULL) expect_identical(fun(), 1) expect_identical(fun(2), 2) }) chk/tests/testthat/test-chk-type.R0000644000176200001440000001064314436206156016660 0ustar liggesuserstest_that("vld_s3_class", { expect_true(vld_s3_class(1, "numeric")) expect_false(vld_s3_class(1L, "numeric")) expect_true(vld_s3_class(1L, "integer")) x <- list() class(x) <- c("a", "b") expect_true(vld_s3_class(x, "a")) expect_true(vld_s3_class(x, "b")) expect_false(vld_s3_class(getClass("MethodDefinition"), "classRepresentation")) }) test_that("chk_s3_class", { expect_identical(chk_s3_class(1L, "integer"), 1L, "integer") expect_invisible(chk_s3_class(1L, "integer")) expect_chk_error(chk_s3_class(1, "integer"), "^`1` must inherit from S3 class 'integer'[.]$") expect_chk_error( chk_s3_class(matrix(1), "numeric"), "`matrix[(]1[)]` must inherit from S3 class 'numeric'[.]$" ) x <- list() class(x) <- c("a", "b") expect_chk_error(chk_s3_class(x, "c"), "`x` must inherit from S3 class 'c'") expect_chk_error(chk_s3_class(x, "c", x_name = "c"), "C must inherit from S3 class 'c'") }) test_that("vld_s4_class", { expect_false(vld_s4_class(1, "numeric")) expect_true(vld_s4_class(getClass("MethodDefinition"), "classRepresentation")) }) test_that("chk_s4_class", { expect_identical( chk_s4_class(getClass("MethodDefinition"), "classRepresentation"), getClass("MethodDefinition"), "classRepresentation" ) expect_invisible(chk_s4_class(getClass("MethodDefinition"), "classRepresentation")) expect_chk_error(chk_s4_class(1, "integer"), "^`1` must inherit from S4 class 'integer'[.]$") expect_chk_error( chk_s4_class(matrix(1), "numeric"), "`matrix[(]1[)]` must inherit from S4 class 'numeric'[.]$" ) }) test_that("vld_whole_numeric", { expect_true(vld_whole_numeric(numeric(0))) expect_true(vld_whole_numeric(integer(0))) expect_false(vld_whole_numeric(logical(0))) expect_true(vld_whole_numeric(Inf)) expect_true(vld_whole_numeric(NA_integer_)) expect_true(vld_whole_numeric(NA_real_)) expect_false(vld_whole_numeric(NA)) expect_true(vld_whole_numeric(1)) expect_true(vld_whole_numeric(1L)) expect_false(vld_whole_numeric(1.1)) expect_false(vld_whole_numeric(-1.1)) expect_true(vld_whole_numeric(c(1, 2))) expect_false(vld_whole_numeric(TRUE)) }) test_that("chk_whole_numeric", { expect_identical(chk_whole_numeric(1L), 1L) expect_invisible(chk_whole_numeric(1L)) expect_identical(chk_whole_numeric(1), 1) expect_identical(chk_whole_numeric(Inf), Inf) expect_chk_error(chk_whole_numeric(TRUE), "^`TRUE` must be a whole numeric vector [(]integer vector or double equivalent[)][.]$") expect_chk_error(chk_whole_numeric(TRUE, x_name = "`c(1,2)`"), "^`c[(]1,2[)]` must be a whole numeric vector [(]integer vector or double equivalent[)][.]$") }) test_that("vld_list", { expect_true(vld_list(list())) expect_true(vld_list(list(1))) expect_true(vld_list(list(x = 1))) x <- list(x = 1) class(x) <- "nlist" expect_true(vld_list(x)) expect_false(vld_list(1)) }) test_that("chk_list", { expect_identical(chk_list(list()), list()) expect_invisible(chk_list(list())) expect_chk_error(chk_list(1), "^`1` must be a list[.]$") expect_chk_error(chk_list(1, x_name = "`list()`"), "^`list[(][)]` must be a list[.]$") }) test_that("vld_function", { expect_true(vld_function(c)) expect_true(vld_function(function() {})) expect_false(vld_function(1)) expect_true(vld_function(function() {}, formals = 0)) expect_false(vld_function(function() {}, formals = 1)) expect_true(vld_function(function(x = 1) {}, formals = 1)) expect_false(vld_function(function(x = 1, y = 3) {}, formals = 1)) }) test_that("chk_function", { expect_identical(chk_function(c), c) expect_invisible(chk_function(c)) expect_chk_error(chk_function(1), "^`1` must be a function[.]$") expect_chk_error(chk_function(1, x_name = "Function()"), "^Function[(][)] must be a function[.]$") expect_chk_error( chk_function(mean, formals = 3), "^`mean` must have 3 formal arguments [(]not 2[)][.]$" ) }) test_that("vld_scalar", { expect_true(vld_scalar(1)) expect_true(vld_scalar(NA)) expect_false(vld_scalar(integer(0))) expect_false(vld_scalar(1:2)) expect_false(vld_scalar(list())) expect_true(vld_scalar(list(x = 1))) expect_true(vld_scalar(matrix(1))) expect_false(vld_scalar(matrix(1:2))) expect_true(vld_scalar(data.frame(x = 1:10))) expect_false(vld_scalar(data.frame(x = 1, y = 2))) }) test_that("chk_scalar", { expect_identical(chk_scalar(1), 1) expect_invisible(chk_scalar(1)) expect_chk_error(chk_scalar(1:2), "^`1:2` must be a scalar [(]length 1[)][.]$") }) chk/tests/testthat/test-check-dim.R0000644000176200001440000000451514436206156016761 0ustar liggesuserstest_that("check_dim length", { expect_identical(check_dim(1), 1) expect_invisible(check_dim(1)) expect_chk_error( check_dim(1:2, dim = identity), "`dim[(]x[)]` must be a whole number [(]non-missing integer scalar or double equivalent[)][.]" ) expect_identical(check_dim(integer(0)), integer(0)) expect_chk_error( check_dim(integer(0), values = TRUE), "^`length[(]integer[(]0[)][)]` must be greater than 0, not 0[.]$" ) expect_chk_error( check_dim(1, values = FALSE), "^`length[(]1[)]` must be equal to 0L[.]" ) expect_identical(check_dim(2, values = 1), check_dim(2, values = 1)) expect_chk_error( check_dim(1, values = 2), "^`length[(]1[)]` must be equal to 2[.]" ) expect_chk_error( check_dim(1, values = 2:3), "^`length[(]1[)]` must be between 2 and 3, not 1[.]" ) expect_chk_error( check_dim(1, values = 3:2), "^`length[(]1[)]` must be between 2 and 3, not 1[.]" ) expect_identical(check_dim(1:2, values = 2:3), check_dim(1:2, values = 2:3)) expect_chk_error( check_dim(2, values = c(2, 2)), "`length[(]2[)]` must be equal to 2[.]" ) expect_chk_error( check_dim(2, values = c(2, 2, 2)), "`length[(]2[)]` must match 2, not 1[.]" ) expect_chk_error( check_dim(2, values = c(3, 2, 2)), "`length[(]2[)]` must match 2 or 3, not 1[.]" ) expect_chk_error( check_dim(1, values = 1.1), "^At least one of the following conditions must be met:\n[*] `values` must be a flag [(]TRUE or FALSE[)].\n[*] `values` must be a whole numeric vector \\(integer vector or double equivalent\\)\\.$" ) }) test_that("check_dim nrow", { expect_identical( check_dim(data.frame(x = 1), dim = nrow), check_dim(data.frame(x = 1), dim = nrow) ) expect_invisible(check_dim(data.frame(x = 1), dim = nrow)) expect_chk_error( check_dim(data.frame(x = integer(0)), values = TRUE, dim = nrow), "`nrow[(]data.frame[(]x = integer[(]0[)][)][)]` must be greater than 0, not 0[.]" ) expect_chk_error( check_dim(data.frame(x = integer(0)), dim = nrow, dim_name = "ncol", values = TRUE), "`ncol[(]data.frame[(]x = integer[(]0[)][)][)]` must be greater than 0, not 0[.]" ) expect_chk_error( check_dim(data.frame(x = integer(0)), dim = nrow, x_name = "y", dim_name = "ncol", values = TRUE), "`ncol[(]y[)]` must be greater than 0, not 0[.]" ) }) chk/tests/testthat/test-chk-chr.R0000644000176200001440000000120314436206156016443 0ustar liggesuserstest_that("vld_chr", { rlang::local_options(lifecycle_verbosity = "quiet") lifecycle::expect_deprecated(chk_chr("")) expect_false(vld_chr(character(0))) expect_true(vld_chr(NA_character_)) expect_true(vld_chr("")) expect_true(vld_chr("a")) expect_false(vld_chr(c("a", "b"))) }) test_that("chk_chr", { rlang::local_options(lifecycle_verbosity = "quiet") lifecycle::expect_deprecated(chk_chr("")) expect_identical(chk_chr(""), "") expect_invisible(chk_chr("")) expect_chk_error(chk_chr(1), "^`1` must be a character scalar[.]$") expect_chk_error(chk_chr(1, x_name = "''"), "^'' must be a character scalar[.]$") }) chk/tests/testthat/test-chk-range.R0000644000176200001440000000727314436206156017000 0ustar liggesuserstest_that("vld_range", { expect_true(vld_range(numeric(0))) expect_true(vld_range(numeric(0), c(1, 1))) expect_true(vld_range(NA_real_)) expect_true(vld_range(1)) expect_true(vld_range(1:3 / 3)) expect_true(vld_range(numeric(0), 1L)) expect_false(vld_range(-1)) expect_true(vld_range(c(-1, -1), c(-2, -1))) expect_true(vld_range(c(NA, 1), 1:2)) }) test_that("chk_range", { expect_identical(chk_range(1), 1) expect_invisible(chk_range(1)) expect_chk_error(chk_range(-1), "^`-1` must be between 0 and 1, not -1[.]$") expect_chk_error(chk_range(c(-1, NA)), "^`c[(]-1, NA[)]` must have values between 0 and 1[.]$") expect_chk_error(chk_range(2, c(1, 1)), "^`2` must be 1, not 2[.]$") expect_chk_error(chk_range(c(2, 1), c(1, 1)), "^`c[(]2, 1[)]` must have values of 1[.]$") expect_chk_error(chk_range(2, c(1, 1), x_name = 1), "^1 must be 1, not 2[.]$") expect_chk_error(chk_range(-1, inclusive = FALSE), "^`-1` must be between 0 and 1 exclusive, not -1[.]$") expect_chk_error(chk_range(c(-1, NA), inclusive = FALSE), "^`c[(]-1, NA[)]` must have values between 0 and 1 exclusive[.]$") expect_chk_error(chk_range(2, c(1, 1), inclusive = FALSE), "^`2` must be between 1 and 1 exclusive, not 2[.]$") expect_chk_error(chk_range(c(2, 1), c(1, 1), inclusive = FALSE), "^`c[(]2, 1[)]` must have values between 1 and 1 exclusive[.]$") expect_chk_error(chk_range(2, c(3, 4), inclusive = FALSE, x_name = 1), "^1 must be between 3 and 4 exclusive, not 2[.]$") }) test_that("vld_lt", { expect_true(vld_lt(numeric(0))) expect_true(vld_lt(NA)) expect_true(vld_lt(-1)) expect_true(vld_lt(c(-1, -Inf))) expect_false(vld_lt(0)) expect_false(vld_lt(1)) }) test_that("chk_lt", { expect_identical(chk_lt(-1), -1) expect_invisible(chk_lt(-1)) expect_chk_error(chk_lt(1), "^`1` must be less than 0, not 1[.]$") expect_chk_error(chk_lt(c(1, -1)), "^`c[(]1, -1[)]` must have values less than 0[.]$") expect_chk_error(chk_lt(1, x_name = -1), "^-1 must be less than 0, not 1[.]$") }) test_that("vld_lte", { expect_true(vld_lte(numeric(0))) expect_true(vld_lte(NA)) expect_true(vld_lte(-1)) expect_true(vld_lte(c(-1, -Inf))) expect_true(vld_lte(0)) expect_false(vld_lte(1)) }) test_that("chk_lte", { expect_identical(chk_lte(-1), -1) expect_invisible(chk_lte(-1)) expect_chk_error(chk_lte(1), "^`1` must be less than or equal to 0, not 1[.]$") expect_chk_error(chk_lte(c(1, -1)), "^`c[(]1, -1[)]` must have values less than or equal to 0[.]$") expect_chk_error(chk_lte(1, x_name = "0"), "^0 must be less than or equal to 0, not 1[.]$") }) test_that("vld_gt", { expect_true(vld_gt(numeric(0))) expect_true(vld_gt(NA)) expect_true(vld_gt(1)) expect_true(vld_gt(c(1, Inf))) expect_false(vld_gt(0)) expect_false(vld_gt(-1)) }) test_that("chk_gt", { expect_identical(chk_gt(1), 1) expect_invisible(chk_gt(1)) expect_chk_error(chk_gt(-1), "^`-1` must be greater than 0, not -1[.]$") expect_chk_error(chk_gt(c(1, -1)), "^`c[(]1, -1[)]` must have values greater than 0[.]$") expect_chk_error(chk_gt(-1, x_name = "`a number`"), "^`a number` must be greater than 0, not -1[.]$") }) test_that("vld_gte", { expect_true(vld_gte(numeric(0))) expect_true(vld_gte(NA)) expect_true(vld_gte(1)) expect_true(vld_gte(c(1, Inf))) expect_true(vld_gte(0)) expect_false(vld_gte(-1)) }) test_that("chk_gte", { expect_identical(chk_gte(1), 1) expect_invisible(chk_gte(1)) expect_chk_error(chk_gte(-1), "^`-1` must be greater than or equal to 0, not -1[.]$") expect_chk_error(chk_gte(c(1, -1)), "^`c[(]1, -1[)]` must have values greater than or equal to 0[.]$") expect_chk_error(chk_gte(-1, x_name = "another number"), "^Another number must be greater than or equal to 0, not -1[.]$") }) chk/tests/testthat/test-chk-environment.R0000644000176200001440000000077214436206156020245 0ustar liggesuserstest_that("vld_environment", { expect_false(vld_environment(1)) expect_false(vld_environment(list(1))) expect_true(vld_environment(.GlobalEnv)) expect_true(vld_environment(environment())) }) test_that("chk_environment", { expect_identical(chk_environment(.GlobalEnv), .GlobalEnv) expect_invisible(chk_environment(.GlobalEnv)) expect_chk_error(chk_environment(1), "^`1` must be an environment[.]$") expect_chk_error(chk_environment(list(1), x_name = 1), "^1 must be an environment[.]$") }) chk/tests/testthat/test-chk-not-subset.R0000644000176200001440000000156014436206156020000 0ustar liggesuserstest_that("vld_not_subset", { expect_true(vld_not_subset(integer(0), 1)) expect_true(vld_not_subset(1, 2)) expect_false(vld_not_subset(1:3, 1:2)) expect_true(vld_not_subset(numeric(0), 1L)) expect_true(vld_not_subset(-1, c(0, 1, NA))) expect_true(vld_not_subset(1L, 0L)) expect_true(vld_not_subset(1, NA)) expect_false(vld_not_subset(c(NA, 1), 1)) expect_false(vld_not_subset(NA, NA)) expect_false(vld_not_subset(c(NA, 1), 1:2)) }) test_that("chk_not_subset", { expect_identical(chk_not_subset(integer(0), 1), integer(0), 1) expect_invisible(chk_not_subset(integer(0), 1)) expect_chk_error(chk_not_subset(1:3, c(0, 1, NA)), "`1:3` must not have any values matching 0, 1 or NA[.]$") expect_chk_error(chk_not_subset(1, c(0, 1, NA)), "^`1` must not match 1, 0 or NA[.]$") expect_chk_error(chk_not_subset(0L, 0L), c("^`0L` must not match 0[.]$")) }) chk/tests/testthat/test-chk-date.R0000644000176200001440000000110214436206156016602 0ustar liggesuserstest_that("vld_date", { expect_false(vld_date(NULL)) expect_false(vld_date(as.Date("2000-01-01")[-1])) expect_false(vld_date(as.Date("2000-01-01")[c(1, 1)])) expect_true(vld_date(as.Date("2000-01-01"))) }) test_that("chk_date", { expect_identical(chk_date(as.Date("2000-01-01")), as.Date("2000-01-01")) expect_invisible(chk_date(as.Date("2000-01-01"))) expect_chk_error(chk_date(1), "^`1` must be a date [(]non-missing Date scalar[)][.]$") expect_chk_error(chk_date(1, x_name = "2001-02-04"), "^2001-02-04 must be a date [(]non-missing Date scalar[)][.]$") }) chk/tests/testthat/test-chk-double.R0000644000176200001440000000064214436206156017147 0ustar liggesuserstest_that("vld_double", { expect_true(vld_double(1)) expect_true(vld_double(matrix(c(1, 2)))) expect_true(vld_double(double(0))) expect_true(vld_double(NA_real_)) expect_false(vld_double(1L)) expect_false(vld_double(TRUE)) }) test_that("chk_double", { expect_identical(chk_double(1), 1) expect_invisible(chk_double(1)) expect_chk_error( chk_double(TRUE), "^`TRUE` must be double[.]$" ) }) chk/tests/testthat/test-chk-whole-number.R0000644000176200001440000000130014436206156020271 0ustar liggesuserstest_that("vld_whole_number", { expect_chk_error(chk_whole_number(1.1), "^`1.1` must be a whole number [(]non-missing integer scalar or double equivalent[)][.]$") expect_chk_error(chk_whole_number(1.1, x_name = 1L), "^1 must be a whole number [(]non-missing integer scalar or double equivalent[)][.]$") }) test_that("chk_whole_number", { expect_identical(chk_whole_number(1), 1) expect_invisible(chk_whole_number(1)) expect_chk_error(chk_whole_number(1.1), "^`1.1` must be a whole number [(]non-missing integer scalar or double equivalent[)][.]$") expect_chk_error(chk_whole_number(1.1, x_name = 1L), "^1 must be a whole number [(]non-missing integer scalar or double equivalent[)][.]$") }) chk/tests/testthat/test-chk-join.R0000644000176200001440000000416314436206156016636 0ustar liggesuserstest_that("vld_join", { expect_true(vld_join(data.frame(z = 1), data.frame(z = 1:2), by = "z")) expect_false(vld_join(data.frame(z = 1), data.frame(z = 2), by = "z")) expect_true(vld_join(data.frame(z = 1:2), data.frame(z = 1:2), by = "z")) }) test_that("vld_join with by = NULL", { expect_false(vld_join(data.frame(z = 1), data.frame(z = 1:2), by = NULL)) }) test_that("vld_join with names", { expect_true(vld_join(data.frame(z = 1), data.frame(a = 1:2), by = c(z = "a"))) expect_false(vld_join(data.frame(z = 1), data.frame(a = 2), by = c(z = "a"))) expect_error( vld_join(data.frame(z = 1), data.frame(a = 2), by = c(a = "z")), "undefined columns selected" ) expect_true(vld_join(data.frame(z = 1, z2 = 2), data.frame(z = 1:2, z2 = 2:1), by = "z")) expect_true(vld_join(data.frame(z = 1, z2 = 2), data.frame(z = 1:2, z2 = 2:1), by = c("z", "z2"))) expect_true(vld_join(data.frame(z = 1, z2 = 2), data.frame(z = 1:2, z2 = 1:2), by = "z")) expect_false(vld_join(data.frame(z = 1, z2 = 2), data.frame(z = 1:2, z2 = 1:2), by = c("z", "z2"))) }) test_that("vld_join with zero length", { expect_true(vld_join(data.frame(z = numeric(0)), data.frame(z = 2), by = c("z"))) expect_true(vld_join(data.frame(z = numeric(0)), data.frame(z = numeric(0)), by = c("z"))) expect_false(vld_join(data.frame(z = 1), data.frame(z = numeric(0)), by = c("z"))) }) test_that("vld_join with missing values", { expect_false(vld_join(data.frame(z = NA_integer_), data.frame(z = 2), by = c("z"))) expect_false(vld_join(data.frame(z = 2), data.frame(z = NA_integer_), by = c("z"))) expect_true(vld_join(data.frame(z = NA_integer_), data.frame(z = NA_integer_), by = c("z"))) }) test_that("chk_join", { expect_identical( chk_join(data.frame(z = 1), data.frame(z = 1), by = "z"), chk_join(data.frame(z = 1), data.frame(z = 1), by = "z") ) expect_invisible(chk_join(data.frame(z = 1), data.frame(z = 1), by = "z")) }) test_that("chk_join", { expect_chk_error( chk_join(data.frame(z = 1), data.frame(z = 2), by = "z"), "^All rows in `data.frame[(]z [=] 1[)]` must match at least one in the y object of class ][.]\n" ) expect_chk_error( chk_identical(1, 1:100), "^`1` must be identical to the y object of class [<]int[>][.]\n" ) expect_chk_error( chk_identical(1, c(1, 5, 1, 9)), "^`1` must be identical to the y object of class [<]dbl[>][.]\n" ) expect_chk_error( chk_identical(1, 2, x_name = 2), "^2 must be identical to 2[.]\n" ) }) test_that("vld_equal", { expect_true(vld_equal(1, 1)) expect_true(vld_equal(1L, 1L)) expect_true(vld_equal(1, 1L)) expect_true(vld_equal(1L, 1)) expect_true(vld_equal(c(1L), 1L)) expect_false(vld_equal(c(x = 1L), 1L)) expect_false(vld_equal(1L, c(x = 1L))) expect_true(vld_equal(1, 1.00000001)) expect_true(vld_equal(1, 1.001, 0.01)) expect_false(vld_equal(1, 1.001, 0.0001)) }) test_that("chk_equal", { expect_identical(chk_equal(1, 1), 1, 1) expect_invisible(chk_equal(1, 1)) expect_chk_error( chk_equal(c(x = 1L), 1L), "^`c[(]x = 1L[)]` must be equal to 1L[.]\n" ) expect_chk_error( chk_equal(1L, 2), "^`1L` must be equal to 2[.]\n" ) expect_chk_error( chk_equal(1, c(1, 5, 1, 9)), "^`1` must be equal to the y object of class [<]dbl[>][.]\n" ) expect_chk_error( chk_equal(1, 2, x_name = 2), "^2 must be equal to 2[.]\n" ) }) test_that("vld_equivalent", { expect_true(vld_equivalent(1, 1)) expect_true(vld_equivalent(1L, 1L)) expect_true(vld_equivalent(1, 1L)) expect_true(vld_equivalent(1L, 1)) expect_true(vld_equivalent(c(1L), 1L)) expect_true(vld_equivalent(c(x = 1L), 1L)) expect_true(vld_equivalent(c(x = 1L), 1L)) expect_true(vld_equivalent(1L, c(x = 1L))) expect_true(vld_equivalent(1L, c(x = 1L))) expect_true(vld_equivalent(1, 1.00000001)) expect_true(vld_equivalent(1, 1.001, 0.01)) expect_false(vld_equivalent(1, 1.001, 0.0001)) }) test_that("chk_equivalent", { expect_identical(chk_equivalent(1, 1), 1, 1) expect_invisible(chk_equivalent(1, 1)) expect_chk_error(chk_equivalent(1, 1.001, 0.0001), c("^`1` must be equivalent to 1[.]001[.]\n")) expect_chk_error( chk_equivalent(1, c(1, 5, 1, 9)), "^`1` must be equivalent to the y object of class [<]dbl[>][.]\n" ) expect_chk_error( chk_equivalent(1, 2, x_name = 2), "^2 must be equivalent to 2[.]\n" ) }) chk/tests/testthat/test-chk-matrix.R0000644000176200001440000000063014436206156017176 0ustar liggesuserstest_that("vld_matrix", { expect_false(vld_matrix(1)) expect_false(vld_matrix(array(1))) expect_true(vld_matrix(matrix())) expect_true(vld_matrix(matrix(NA))) expect_true(vld_matrix(matrix(1))) }) test_that("chk_matrix", { expect_identical(chk_matrix(matrix(1)), matrix(1)) expect_invisible(chk_matrix(matrix(1))) expect_chk_error( chk_matrix(1), "^`1` must be an matrix[.]$" ) }) chk/tests/testthat/test-chk-subset.R0000644000176200001440000000301214436206156017174 0ustar liggesuserstest_that("vld_subset", { expect_true(vld_subset(integer(0), 1)) expect_false(vld_subset(1:3, 1:2)) expect_true(vld_subset(numeric(0), 1L)) expect_false(vld_subset(-1, c(0, 1, NA))) expect_false(vld_subset(1L, 0L)) expect_false(vld_subset(1, NA)) expect_false(vld_subset(c(NA, 1), 1)) expect_true(vld_subset(NA, NA)) expect_true(vld_subset(c(NA, 1), c(1, NA))) expect_false(vld_subset(c(NA, 1), 1:2)) }) test_that("chk_subset", { expect_identical(chk_subset(integer(0), 1), integer(0), 1) expect_invisible(chk_subset(integer(0), 1)) expect_chk_error(chk_subset(NA, c(0, Inf)), "^`NA` must match 0 or Inf, not NA[.]$") expect_chk_error(chk_subset(1:3, c(0, 1, NA)), "`1:3` must have values matching 0, 1 or NA[.]$") expect_chk_error(chk_subset(-1, c(0, 1, NA)), "^`-1` must match 0, 1 or NA, not -1[.]$") expect_chk_error(chk_subset(c(1L, 1L), 0L), c("^`c[(]1L, 1L[)]` must have values matching 0[.]$")) expect_chk_error(chk_subset(1, ""), "^`1` must match '', not 1[.]$") expect_chk_error( chk_subset(1, NA), "^`1` must match NA, not 1[.]$" ) expect_chk_error( chk_subset(c(NA, 1), 1), "^`c[(]NA, 1[)]` must have values matching 1[.]$" ) expect_chk_error( chk_subset(c(NA, 1), 1:2), "^`c[(]NA, 1[)]` must have values matching 1 or 2[.]$" ) expect_chk_error( chk_subset(3L, values = c(1L, 1L, 7L)), "^`3L` must match 1 or 7, not 3[.]$" ) expect_chk_error( chk_subset(3L, values = c(1L, 1L, 7L), x_name = "1"), "^1 must match 1 or 7, not 3[.]$" ) }) chk/tests/testthat/test-check-data.R0000644000176200001440000000273214436206156017120 0ustar liggesuserstest_that("check_data works", { expect_identical(check_data(data.frame()), data.frame()) expect_invisible(check_data(data.frame())) expect_identical(check_data(data.frame(x = 1)), data.frame(x = 1)) expect_identical( check_data(data.frame(x = 1, values = list(x = 1))), check_data(data.frame(x = 1, values = list(x = 1))) ) expect_identical(check_data(data.frame(x = 1), nrow = c(1, Inf)), data.frame(x = 1)) }) test_that("check_data fails", { expect_chk_error( check_data(data.frame(), nrow = TRUE), "`nrow[(]`data.frame[(][)]`[)]` must be greater than 0, not 0." ) expect_chk_error( check_data(data.frame(), values = list(x = 1)), "`names[(]data.frame[(][)][)]` must include 'x'." ) expect_chk_error(check_data(data.frame(x = 1, y = 2), values = list(x = 1), exclusive = TRUE), "^`names[(]data.frame[(]x = 1, y = 2[)][)]` must not include 'y'[.]$") expect_chk_error( check_data(data.frame(x = 1), values = list(x = 1L)), "`data.frame[(]x = 1[)][$]x` must inherit from S3 class 'integer'." ) expect_chk_error( check_data(data.frame(x = c(1, 1)), key = "x"), "^Column 'x' in `data.frame[(]x = c[(]1, 1[)][)]` must be a unique key[.]$" ) expect_chk_error( check_data(data.frame(x = ordered(1:2)), values = list(x = ordered(1:2, levels = 2:1))), "^`levels[(]data.frame[(]x = ordered[(]1:2[)][)][$]x[)]` must have [(]the first occurence of[)] each of the following elements in the following order: '2', '1'[.]$" ) }) chk/tests/testthat/test-err.R0000644000176200001440000000614714436206156015730 0ustar liggesuserstest_that("message_chk", { expect_match(message_chk(), "^[.]$") expect_match(message_chk("", ""), "^[.]$") expect_match(message_chk("a"), "^A[.]$") expect_match(message_chk("`a`"), "^`a`[.]$") expect_match(message_chk("a", "b"), "^Ab[.]$") expect_match(message_chk(" a", " b"), "^ a b[.]$") expect_match(message_chk(" A", "b"), "^ Ab[.]$") expect_match(message_chk("Ab", "b"), "^Abb[.]$") expect_match(message_chk("Ab.", "b."), "^Ab[.]b[.]$") expect_match(message_chk("a"), "^A[.]$") expect_match(message_chk("a."), "^A[.]$") expect_match(message_chk("a!"), "^A!$") expect_match(message_chk("a?"), "^A[?]$") expect_match( message_chk("there %r %n problem director%y%s", n = 1), "There is 1 problem directory[.]$" ) expect_match( message_chk("there %r %n problem director%y%s", n = 2), "There are 2 problem directories[.]$" ) expect_match( message_chk("there %r %n problem director%y%s", n = 1.5), "There are 1.5 problem directories[.]$" ) expect_match( message_chk("there %r %n problem director%y%s", n = 0), "There are 0 problem directories[.]$" ) expect_match( message_chk("there %r %n problem director%y%s", n = 0, tidy = FALSE), "there are 0 problem directories$" ) }) test_that("err", { expect_error(err(), "^[.]$") expect_error(err("this", "is"), "^Thisis[.]$") expect_error( err("There %r %n problem value%s"), "There %r %n problem value%s[.]$" ) expect_error( err("there %r %n problem value%s", n = 2), "There are 2 problem values[.]$" ) expect_error( err("there %r %n problem value%s", n = 0, tidy = FALSE), "there are 0 problem values$" ) }) test_that("err .subclass deprecated", { lifecycle::expect_deprecated(expect_s3_class(expect_error(err(.subclass = "xx"), "^[.]$"), "xx")) expect_s3_class(expect_error(err(class = "xx"), "^[.]$"), "xx") }) test_that("msg", { expect_message(msg(), "^[.]") expect_message(msg("this", "is"), "^Thisis[.]") expect_message( msg("There %r %n problem value%s"), "^There %r %n problem value%s[.]" ) expect_message( msg("there %r %n problem value%s", n = 2), "^There are 2 problem values[.]" ) expect_message( msg("there %r %n problem value%s", n = 0, tidy = FALSE), "there are 0 problem values" ) }) test_that("msg .subclass deprecated", { lifecycle::expect_deprecated(expect_s3_class(expect_message(msg(.subclass = "xx"), "^[.]$"), "xx")) expect_s3_class(expect_message(msg(class = "xx"), "^[.]$"), "xx") }) test_that("wrn", { expect_warning(wrn(), "^[.]$") expect_warning(wrn("this", "is"), "^Thisis[.]$") expect_warning( wrn("there %r %n problem value%s"), "^There %r %n problem value%s." ) expect_warning( wrn("there %r %n problem value%s", n = 2), "^There are 2 problem values[.]$" ) expect_warning( wrn("there %r %n problem value%s", n = 0, tidy = FALSE), "there are 0 problem values$" ) }) test_that("wrn .subclass deprecated", { lifecycle::expect_deprecated(expect_s3_class(expect_warning(wrn(.subclass = "xx"), "^[.]$"), "xx")) expect_s3_class(expect_warning(wrn(class = "xx"), "^[.]$"), "xx") }) chk/tests/testthat/test-chk-sorted.R0000644000176200001440000000102514436206156017171 0ustar liggesuserstest_that("vld_sorted", { expect_true(vld_sorted(TRUE)) expect_true(vld_sorted(1)) expect_true(vld_sorted(character(0))) expect_true(vld_sorted(NA)) expect_true(vld_sorted(1:2)) expect_false(vld_sorted(2:1)) expect_true(vld_sorted(c(1:2, NA))) expect_false(vld_sorted(c(2:1, NA))) }) test_that("chk_sorted", { expect_identical(chk_sorted(TRUE), TRUE) expect_invisible(chk_sorted(TRUE)) expect_identical(chk_sorted(c(x = TRUE)), c(x = TRUE)) expect_chk_error(chk_sorted(2:1), "^`2:1` must be sorted[.]$") }) chk/tests/testthat/test-chk-number.R0000644000176200001440000000120314436206156017157 0ustar liggesuserstest_that("vld_number", { expect_false(vld_number(numeric(0))) expect_false(vld_number(NA_integer_)) expect_true(vld_number(1)) expect_true(vld_number(1L)) expect_true(vld_number(1.1)) expect_true(vld_number(-1.1)) expect_true(vld_number(Inf)) expect_false(vld_number(c(1, 2))) expect_false(vld_number(TRUE)) }) test_that("chk_number", { expect_identical(chk_number(1), 1) expect_invisible(chk_number(1)) expect_chk_error(chk_number(TRUE), "^`TRUE` must be a number [(]non-missing numeric scalar[)][.]$") expect_chk_error(chk_number(TRUE, x_name = 1L), "^1 must be a number [(]non-missing numeric scalar[)][.]$") }) chk/tests/testthat/test-chk-character-or-factor.R0000644000176200001440000000120014436206156021512 0ustar liggesuserstest_that("vld_character_or_factor", { expect_true(vld_character_or_factor("1")) expect_true(vld_character_or_factor(matrix("a"))) expect_true(vld_character_or_factor(character(0))) expect_true(vld_character_or_factor(NA_character_)) expect_false(vld_character_or_factor(1)) expect_false(vld_character_or_factor(TRUE)) expect_true(vld_character_or_factor(factor("text"))) }) test_that("chk_character_or_factor", { expect_identical(chk_character_or_factor("1"), "1") expect_invisible(chk_character_or_factor("1")) expect_chk_error( chk_character_or_factor(TRUE), "^`TRUE` must be character or factor[.]$" ) }) chk/tests/testthat/test-chk-tz.R0000644000176200001440000000071714436206156016335 0ustar liggesuserstest_that("chk_tz", { expect_identical(chk_tz("UTC"), "UTC") expect_invisible(chk_tz("UTC")) expect_chk_error( chk_tz("TCU"), "^`\"TCU\"` must be a tz [(]non-missing scalar character of a recognized timezone[)][.]$" ) }) test_that("vld_tz", { expect_true(vld_tz("UTC")) expect_false(vld_tz("TCU")) expect_false(vld_tz(1)) expect_false(vld_tz(character(0))) expect_false(vld_tz(c("UTC", "UTC"))) expect_false(vld_tz(NA_character_)) }) chk/tests/testthat/test-chkor.R0000644000176200001440000000154214436206156016240 0ustar liggesuserstest_that("chkor", { rlang::local_options(lifecycle_verbosity = "quiet") expect_null(chkor()) expect_invisible(chkor()) expect_null(chkor(chk_flag(TRUE))) expect_null(chkor(chk_flag(1), chk_flag(TRUE))) expect_chk_error(chkor(chk_flag(1)), "^`1` must be a flag [(]TRUE or FALSE[)][.]$") expect_chk_error(chkor(chk_flag(1), chk_flag(1)), "^`1` must be a flag [(]TRUE or FALSE[)][.]$") expect_chk_error(chkor(chk_flag(1), chk_flag(2)), "^At least one of the following conditions must be met:\n[*] `1` must be a flag [(]TRUE or FALSE[)][.]\n[*] `2` must be a flag [(]TRUE or FALSE[)][.]$") expect_chk_error(chkor(chk_flag(1), chk_flag(2), chk_flag(0)), "^At least one of the following conditions must be met:\n[*] `1` must be a flag [(]TRUE or FALSE[)].\n[*] `2` must be a flag [(]TRUE or FALSE[)].\n[*] `0` must be a flag [(]TRUE or FALSE[)].$") }) chk/tests/testthat.R0000644000176200001440000000006214436206156014151 0ustar liggesuserslibrary(testthat) library(chk) test_check("chk") chk/vignettes/0000755000176200001440000000000014507626247013044 5ustar liggesuserschk/vignettes/chk.Rmd0000644000176200001440000000743314436206156014256 0ustar liggesusers--- title: "Get Started with chk" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Get Started with chk} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ## Introduction `chk` is an R package for developers to check user-supplied function arguments. It is designed to be simple, customizable and fast. ### `chk_` Functions `chk_` functions check the properties of individual objects. For example `chk_flag(x)` checks whether `x` is a flag, i.e., a non-missing logical vector of length 1. `chk_` functions are called for their side-effects, i.e., they throw an informative error if the object fails the check. Although do return an invisible copy of the first argument so they can be used in pipes. ```{r, error=TRUE} library(chk) y <- TRUE chk_flag(y) y <- NA chk_flag(y) ``` The error messages, which follow the [tidyverse style guide](https://style.tidyverse.org/error-messages.html), are designed to allow the user to quickly identify the problem with the argument value(s) they are providing. The errors are [rlang errors](https://rlang.r-lib.org/reference/abort.html) of subclass `'chk_error'`. ### `vld_` Functions Each `chk_` function has a matching `vld_` function which returns a flag indicating whether the object passed the check. ```{r, error=TRUE} vld_flag(TRUE) vld_flag(NA) ``` The `vld_` functions allow developers to provide their own error messages. ```{r, error=TRUE} if (!vld_flag(NA)) abort_chk("`NA` is not TRUE or FALSE!!") ``` ## Using chk The `chk_` functions are designed to be used within functions. Consequently, when constructing an error message they use the name of the object that they received as this is expected to be the name of the argument. ```{r, error = TRUE} fun1 <- function(x) { chk_whole_number(x) # use x } fun1(1) y <- 1.3 fun1(x = y) ``` If this is not the case, developers can provide a different name using the `x_name` argument. ```{r, error = TRUE} x <- NA chk_flag(x, x_name = "`zzz`") ``` **IMPORTANT NOTE** As the `chk_` (and `vld_`) functions are not expected to be directly exposed to users they don't check any of their arguments (other than the object of interest of course!) to ensure that they are as fast as possible. ## Extending chk The `chk_flag()` function illustrates the general structure of a `chk_` function. ``` r chk_flag #> function(x, x_name = NULL){ #> if(vld_flag(x)) return(invisible(x)) #> if(is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) #> abort_chk(x_name, " must be a flag (TRUE or FALSE)") #> } #> #> ``` A `chk_` function initially checks the object (using its `vld_` partner) and if the object passes the check immediately returns an invisible copy of the object. If, and only if, the object fails the check does the `chk_` function construct and then throw an informative error message. The `deparse_backtick_chk()` and `abort_chk()` functions are exported to make it easy for programmers to develop their own `chk_` functions. The [chk-lgl.R](https://github.com/poissonconsulting/chk/blob/master/R/chk-lgl.R) script illustrates the general template to use when developing your own `chk_` functions. ### `abort_chk()` The `abort_chk()` function converts multiple arguments to a string using `paste0(..., collapse = '')` and provides number sensitive `sprintf`-like types. By default it also capitalizes the first character and adds a missing period. ```{r, error=TRUE} abort_chk("There %r %n problem director%y%s.", n = 1) abort_chk("there %r %n ", "problem director%y%s", n = 2) ``` ### `check_` Functions The `check_` functions are more complex then the `chk_` functions which make them slower but makes doing some general tests easier. chk/vignettes/chk-families.Rmd0000644000176200001440000001130214436206156016033 0ustar liggesusers--- title: "chk Families" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{chk Families} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` The `chk_` functions (and their `vld_` equivalents) can be divided into the following families. For reasons of space, the `x_name = NULL` argument is not shown. ## Check Logical Function | Code :- | :- `chk_true(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x) && x` `chk_false(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x) && !x` `chk_flag(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x)` `chk_lgl(x)` | `is.logical(x) && length(x) == 1L` ## Check Scalars Function | Code :- | :------ `chk_scalar(x)` | `length(x) == 1L` `chk_number(x)` | `is.numeric(x) && length(x) == 1L && !anyNA(x)` `chk_whole_number(x)` | `vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))` `chk_string(x)` | `is.character(x) && length(x) == 1L && !anyNA(x)` `chk_date(x)` | `inherits(x, "Date") && length(x) == 1L && !anyNA(x)` `chk_datetime(x)` | `inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)` `chk_tz(x)` | `is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames()` ## Check Ranges Function | Code :- | :--- `chk_range(x, range = c(0, 1))` | `all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])` `chk_lt(x, value = 0)` | `all(x[!is.na(x)] < value)` `chk_lte(x, value = 0)` | `all(x[!is.na(x)] <= value)` `chk_gt(x, value = 0)` | `all(x[!is.na(x)] > value)` `chk_gte(x, value = 0)` | `all(x[!is.na(x)] >= value)` ## Check Equals Function | Code :-- | :- `chk_identical(x, y)` | `identical(x, y)` `chk_equal(x, y, tolerance = sqrt(.Machine$double.eps))` | `vld_true(all.equal(x, y, tolerance))` `chk_equivalent(x, y, tolerance = sqrt(.Machine$double.eps))` | `vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))` ## Check Alls Function | Code :- | :--- `chk_all(x, chk_fun, ...)` | `all(vapply(x, chk_fun, TRUE, ...))` `chk_all_identical(x)` | `length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]]))` `chk_all_equal(x, tolerance = sqrt(.Machine$double.eps))` | `length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance))` `chk_all_equivalent(x, tolerance = sqrt(.Machine$double.eps))` | `length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance))` ## Check Set Function | Code :- | :--- `chk_setequal(x, values)` | `setequal(x, values)` `chk_subset(x, values)` | `all(x %in% values)` `chk_superset(x, values)` | `all(values %in% x)` `chk_join(x, y, by)` | `identical(nrow(x), nrow(merge(x, unique(y[if (is.null(names(by))) by else names(by)]), by = by)))` ## Check Is Function | Code :- | :--- `chk_atomic(x)` | `is.atomic(x)` `chk_function(x, formals = NULL)` | `is.function(x) && (is.null(formals) || length(formals(x)) == formals)` `chk_numeric(x)` | `is.numeric(x)` `chk_s3_class(x, class)` | `!isS4(x) && inherits(x, class)` `chk_s4_class(x, class)` | `isS4(x) && methods::is(x, class)` `chk_vector(x)` | `is.vector(x)` `chk_whole_numeric(x)` | `is.integer(x) || (is.double(x) && vld_true(all.equal(x, as.integer(x))))` `chk_array(x)` | `is.array(x)` `chk_matrix(x)` | `is.matrix(x)` `chk_data(x)` | `inherits(x, "data.frame")` ## Check Typeof Function | Code :- | :--- `chk_environment(x)` | `is.environment(x)` `chk_list(x)` | `is.list(x)` `chk_logical(x)` | `is.logical(x)` `chk_double(x)` | `is.double(x)` `chk_integer(x)` | `is.integer(x)` `chk_character(x)` | `is.character(x)` ## Check NULLs Function | Code :- | :--- `chk_null(x)` | `is.null(x)` `chk_not_null(x)` | `!is.null(x)` ## Check Ellipsis Function | Code :- | :--- `chk_used(...)` | `length(list(...)) != 0L` `chk_unused(...)` | `length(list(...)) == 0L` ## Check Files Function | Code :- | :--- `chk_file(x)` | `vld_string(x) && file.exists(x) && !dir.exists(x)` `chk_ext(x, ext)` | `vld_string(x) && vld_subset(tools::file_ext(x), ext)` `chk_dir(x)` | `vld_string(x) && dir.exists(x)` ## Check Miscellaneous Function | Code :- | :-- `chk_match(x, regexp = ".+")` | `all(grepl(regexp, x[!is.na(x)]))` `chk_named(x)` | `!is.null(names(x))` `chk_not_empty(x)` | `length(x) != 0L` `chk_not_any_na(x)` | `!anyNA(x)` `chk_unique(x, incomparables = FALSE)` | `!anyDuplicated(x, incomparables = incomparables)` `chk_sorted(x)` | `is.unsorted(x)` ## Check **Function** `check_data(x, values = NULL, exclusive = FALSE, order = FALSE, nrow = numeric(0), key = character(0))` `check_dim(x, dim = length, values = numeric(0), dim_name = NULL)` `check_key(x, key = character(0), na_distinct = FALSE)` `check_names(x, names = character(0), exclusive = FALSE, order = FALSE)` `check_values(x, values)` chk/R/0000755000176200001440000000000014506604660011227 5ustar liggesuserschk/R/chk-not-empty.R0000644000176200001440000000166114436206156014055 0ustar liggesusers#' 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()`. #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_not_empty #' chk_not_empty(1) #' try(chk_not_empty(numeric(0))) #' @export chk_not_empty <- function(x, x_name = NULL) { if (vld_not_empty(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must not be empty (zero length)", x = x) } #' @describeIn chk_not_empty Validate Not Empty #' #' @examples #' # vld_not_empty #' vld_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()) #' @export vld_not_empty <- function(x) length(x) != 0L chk/R/chk-match.R0000644000176200001440000000200214436206156013203 0ustar liggesusers#' Check Matches #' #' @description #' Checks if all values match regular expression using #' #' `all(grepl(regexp, x[!is.na(x)]))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_match #' chk_match("1") #' try(chk_match("1", regexp = "2")) #' @export chk_match <- function(x, regexp = ".+", x_name = NULL) { if (vld_match(x, regexp)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk(x_name, " must match regular expression '", regexp, "'", x = x, regexp = regexp) } abort_chk(x_name, " must have values matching regular expression '", regexp, "'", x = x, regexp = regexp) } #' @describeIn chk_match Validate Matches #' #' @examples #' # vld_match #' vld_match("1") #' vld_match("a", regexp = "a") #' vld_match("") #' vld_match("1", regexp = "2") #' vld_match(NA_character_, regexp = ".*") #' @export vld_match <- function(x, regexp = ".+") all(grepl(regexp, x[!is.na(x)])) chk/R/chk-whole-numeric.R0000644000176200001440000000204714436206156014676 0ustar liggesusers#' 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))))` #' #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_whole_numeric #' chk_whole_numeric(1) #' try(chk_whole_numeric(1.1)) #' @export chk_whole_numeric <- function(x, x_name = NULL) { if (vld_whole_numeric(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk( x_name, " must be a whole numeric vector (integer vector or double equivalent)", x = x ) } #' @describeIn chk_whole_numeric Validate Whole Numeric #' #' @examples #' # vld_whole_numeric #' vld_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) #' @export vld_whole_numeric <- function(x) { is.integer(x) || (is.double(x) && vld_true(all.equal(x[!is.na(x)], trunc(x[!is.na(x)])))) } chk/R/chk-identical.R0000644000176200001440000000152114436206156014050 0ustar liggesusers#' Check Identical #' #' @description #' Checks if is identical to y using #' #' `identical(x, y)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_equals #' #' @examples #' # chk_identical #' chk_identical(1, 1) #' try(chk_identical(1, 1L)) #' chk_identical(c(1, 1), c(1, 1)) #' try(chk_identical(1, c(1, 1))) #' @export chk_identical <- function(x, y, x_name = NULL) { if (identical(x, y)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) y_name <- as_label(y) obj_of <- if (grepl("^<", y_name)) "the y object of class " else NULL abort_chk(x_name, " must be identical to ", obj_of, y_name, x = x, y = y ) } #' @describeIn chk_identical Validate Identical #' #' @examples #' vld_identical(1, 1) #' @export vld_identical <- function(x, y) identical(x, y) chk/R/chk-not-missing.R0000644000176200001440000000145514436206156014371 0ustar liggesusers#' Check Not Missing Argument #' #' @description #' Checks argument not missing using #' #' `!missing(x)` #' #' @details #' Currently only checks if value is available #' (as opposed to whether it was specified). #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_not_missing #' fun <- function(x) { #' chk_not_missing(x) #' } #' fun(1) #' try(fun()) #' @export chk_not_missing <- function(x, x_name = "`x`") { if (vld_not_missing(x)) { return(invisible(x)) } abort_chk(x_name, " must not be missing.", tidy = FALSE) } #' @describeIn chk_not_missing Validate Not Missing Argument #' #' @examples #' # vld_not_missing #' fun <- function(x) { #' vld_not_missing(x) #' } #' fun() #' fun(1) #' @export vld_not_missing <- function(x) { !missing(x) } chk/R/check-key.R0000644000176200001440000000223414436206156013216 0ustar liggesusers#' Check Key #' #' @description #' Checks if columns have unique rows. #' #' @inheritParams params #' @param key A character vector of the columns that represent a unique key. #' @param na_distinct A flag specifying whether missing values should be considered distinct. #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @examples #' x <- data.frame(x = c(1, 2), y = c(1, 1)) #' check_key(x) #' try(check_key(x, "y")) #' @export check_key <- function(x, key = character(0), na_distinct = FALSE, x_name = NULL) { chk_data(x) chk_s3_class(key, "character") if (!length(key)) { return(invisible(x)) } chk_unique(key) chk_not_any_na(key) chk_flag(na_distinct) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) check_names(x, key, x_name = x_name) # to ensure not tripped up by sf objects. x <- as.data.frame(x) incomparables <- if (na_distinct) NA else FALSE if (any(new_duplicated(x[key], incomparables = incomparables))) { abort_chk("Column%s ", cc(key, conj = " and "), " in ", x_name, " must be a unique key.", n = length(key)) } invisible(x) } chk/R/chk-length.R0000644000176200001440000000200214507602131013360 0ustar liggesusers#' Check Length #' #' @description #' Checks length is a particular value or range using #' #' `length(x) >= length && length(x) <= upper` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' @seealso [check_dim()] #' #' @examples #' # chk_length #' chk_length("text") #' try(vld_length("text", length = 2)) #' @export chk_length <- function(x, length = 1L, upper = length, x_name = NULL) { if (vld_length(x, length, upper)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length == upper) { abort_chk(x_name, " must be length ", length, " not ", length(x), x = x, length = length) } abort_chk(x_name, " must have a length between ", length, " and ", upper, " not ", length(x), x = x, length = length) } #' @describeIn chk_length Validate Length #' #' @examples #' # vld_length #' vld_length(2:1, 2) #' vld_length(2:1, 1) #' @export vld_length <- function(x, length = 1L, upper = length) length(x) >= length && length(x) <= upper chk/R/chk-vector.R0000644000176200001440000000155114436206156013421 0ustar liggesusers#' Check Vector #' #' @description #' Checks if is a vector using #' #' `(is.atomic(x) && !is.matrix(x) && !is.array(x)) || is.list(x)` #' #' @details #' `is.vector(x)` is not reliable because it returns TRUE only #' if the object is a vector with no attributes apart from names. #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_vector #' chk_vector(1) #' chk_vector(list()) #' try(chk_vector(matrix(1))) #' @export chk_vector <- function(x, x_name = NULL) { if (vld_vector(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a vector", x = x) } #' @describeIn chk_vector Validate Vector #' #' @examples #' # vld_vector #' vld_vector(1) #' @export vld_vector <- function(x) (is.atomic(x) && !is.matrix(x) && !is.array(x)) || is.list(x) chk/R/chk-equal.R0000644000176200001440000000203614436206156013225 0ustar liggesusers#' Check Equal #' #' @description #' Checks if is equal (identical within tolerance) to y using #' #' `vld_true(all.equal(x, y, tolerance))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_equals #' #' @examples #' # chk_equal #' chk_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))) #' @export chk_equal <- function(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL) { if (vld_equal(x, y, tolerance = tolerance)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) y_name <- as_label(y) obj_of <- if (grepl("^<", y_name)) "the y object of class " else NULL abort_chk(x_name, " must be equal to ", obj_of, y_name, x = x, y = y ) } #' @describeIn chk_equal Validate Equal #' #' @examples #' vld_equal(1, 1.00000001) #' @export vld_equal <- function(x, y, tolerance = sqrt(.Machine$double.eps)) { vld_true(all.equal(x, y, tolerance)) } chk/R/template.R0000644000176200001440000000401014436206156013160 0ustar liggesusers#' Parameters for chk functions #' #' Descriptions of the parameters and return values for the chk functions #' #' @keywords internal #' @name params #' #' @param x The object to check. #' @param x_name A string of the name of object x or NULL. #' @param y An object to check against. #' @param chk A flag specifying whether to check the other parameters. #' @param chk_fun A chk_ function. #' @param tolerance A non-negative numeric scalar. #' @param ext A character vector of the permitted file extensions #' (without the .). #' @param exists A flag specifying whether the files/directories must (or must not) exist. #' @param value A non-missing scalar of a value. #' @param range A non-missing sorted vector of length 2 of the lower and #' upper permitted values. #' @param inclusive A flag specifying whether the range is exclusive. #' @param regexp A string of a regular expression. #' @param values A vector of the permitted values. #' @param class A string specifying the class. #' @param length A count of the length. #' @param upper A count of the max length. #' @param formals A count of the number of formal arguments. #' @param incomparables A vector of values that cannot be compared. #' FALSE means that all values can be compared. #' @param by A character vector specifying the column names to join x and y on. #' If named the names are the corresponding columns in x. #' @param exclusive A flag specifying whether x must only include columns named in values. #' @param order A flag specifying whether the order of columns in x must match names in values. #' @param nrow A flag or a whole numeric vector of the value, value range or possible values. #' @param key A character vector of the columns that represent a unique key. #' @param vld_fun A vld_ function. #' @param ... Additional arguments. #' @return #' The `chk_` function throws an informative error if the test fails or #' returns the original object if successful so it can used in pipes. #' #' The `vld_` function returns a flag indicating whether the test was met. NULL chk/R/utils.R0000644000176200001440000000252714436206156012520 0ustar liggesusers#' Abort Check #' #' A wrapper on [err()] that sets the subclass to be `'chk_error'`. #' #' It is exported to allow users to easily construct their own `chk_` functions. #' #' @inheritParams message_chk #' @inheritParams rlang::abort #' @return Throws an error of class `'chk_error'`. #' @seealso [err()] #' @export #' #' @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)) abort_chk <- function(..., n = NULL, tidy = TRUE, call = rlang::caller_call(2)) { err(..., n = n, tidy = tidy, class = "chk_error", call = call) } #' Deparse Backtick #' #' `deparse_backtick_chk` is a wrapper on [deparse()] #' and `backtick_chk`. #' #' It is exported to allow users to easily construct their own `chk_` functions. #' #' @param x A substituted object to deparse. #' #' @return A string of the backticked substituted object. #' @seealso [deparse()] #' @export #' #' @examples #' #' # deparse_backtick_chk #' deparse_backtick_chk(2) #' deparse_backtick_chk(2^2) deparse_backtick_chk <- function(x) backtick_chk(deparse(x)) #' @describeIn deparse_backtick_chk Backtick #' @export backtick_chk <- function(x) p0("`", x, "`") #' @describeIn deparse_backtick_chk Unbacktick #' @export unbacktick_chk <- function(x) gsub("`", "", x) chk/R/chkor.R0000644000176200001440000000107714436206156012465 0ustar liggesusers#' Check OR #' #' The `chkor()` function has been deprecated for the faster `chkor_vld()`. #' #' `r lifecycle::badge("deprecated")` #' #' @param ... Multiple `chk_` functions. #' #' @return An informative error if the test fails. #' #' @seealso [chk_null_or()] #' #' @export #' #' @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)) chkor <- function(...) { lifecycle::deprecate_soft("0.6.1", "chkor()", "chkor_vld()") quos <- enquos(...) invisible(chkor_quos(quos)) } chk/R/p.R0000644000176200001440000000076314436206156011617 0ustar liggesusers#' Concatenate Strings #' #' A wrapper on [base::paste()]. #' #' @inheritParams base::paste #' #' @return A character vector. #' @export #' #' @examples #' p("a", "b") #' p(c("a", "b"), collapse = " ") p <- function(..., sep = " ", collapse = NULL) { paste(..., sep = sep, collapse = collapse) } #' @describeIn p A wrapper on [base::paste0()] #' @export #' #' @examples #' p0("a", "b") #' p0(c("a", "b"), collapse = "") p0 <- function(..., collapse = NULL) { paste0(..., collapse = collapse) } chk/R/deprecated.R0000644000176200001440000001004314436206156013450 0ustar liggesusers#' Deprecated functions #' #' #' Deprecated `chk_()` functions. #' #' @family deprecated #' #' @inheritParams chk_flag #' @keywords internal #' @name chk_deprecated NULL #' @describeIn chk_deprecated Check Directories Exist #' #' `r lifecycle::badge("deprecated")` #' #' Replace with `[chk_all](x, [chk_dir])` #' #' @export chk_dirs <- function(x) { deprecate_warn("0.2.0", what = "chk::chk_dirs()", details = "Please use `chk_all(x, chk_dir)` instead" ) chk_all(x, chk_dir) } #' @describeIn chk_deprecated Check Files Exist #' #' `r lifecycle::badge("deprecated")` #' #' Replace with `[chk_all](x, [chk_file])` #' #' @export chk_files <- function(x) { deprecate_warn("0.2.0", what = "chk::chk_files()", details = "Please use `chk_all(x, chk_file)` instead" ) chk_all(x, chk_file) } #' @describeIn chk_deprecated Check Has #' #' `r lifecycle::badge("deprecated")` #' #' Replace by [chk_superset()] #' #' @export chk_has <- function(x, values, x_name = NULL) { if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_superset(x, values, x_name = x_name) deprecate_warn("0.2.0", what = "chk::chk_has()", with = "chk::chk_superset()" ) invisible() } #' @describeIn chk_deprecated Check In #' #' `r lifecycle::badge("deprecated")` #' #' Replace by [chk_subset()] #' #' @export chk_in <- function(x, values, x_name = NULL) { if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_subset(x, values, x_name = x_name) deprecate_warn("0.2.0", what = "chk::chk_in()", with = "chk::chk_subset()" ) invisible() } #' @describeIn chk_deprecated Check No Missing Values #' #' `r lifecycle::badge("deprecated")` #' #' Replace with [chk_not_any_na()] #' #' @export chk_no_missing <- function(x, x_name = NULL) { deprecate_warn("0.2.0", what = "chk::chk_no_missing()", with = "chk::chk_not_any_na()", id = "chk_no_missing" ) if (vld_no_missing(x)) { return(invisible()) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must not have missing values", x = x) } #' @describeIn chk_deprecated Validate No Missing Values #' #' `r lifecycle::badge("deprecated")` #' #' Replace with [vld_not_any_na()] #' #' @export vld_no_missing <- function(x) { deprecate_warn("0.2.0", what = "chk::vld_no_missing()", with = "chk::vld_not_any_na()", id = "chk_no_missing" ) !anyNA(x) } #' @describeIn chk_deprecated Turns checking off #' #' `r lifecycle::badge("deprecated")` #' #' This approach is no longer recommended #' #' @export chk_off <- function() { deprecate_stop("0.2.0", what = "chk::chk_off()", details = "This approach is no longer recommended" ) options(chk.on = FALSE) } #' @describeIn chk_deprecated Turns checking on #' #' `r lifecycle::badge("deprecated")` #' #' This approach is no longer recommended #' #' @export chk_on <- function() { deprecate_stop("0.2.0", what = "chk::chk_on()", details = "This approach is no longer recommended" ) options(chk.on = TRUE) } #' @describeIn chk_deprecated Tests checking on #' #' `r lifecycle::badge("deprecated")` #' #' This approach is no longer recommended #' #' @export is_chk_on <- function() { deprecate_stop("0.2.0", what = "chk::is_chk_on()", details = "This approach is no longer recommended" ) getOption("chk.on", TRUE) } #' @describeIn chk_deprecated Check Proportion #' #' `r lifecycle::badge("deprecated")` #' #' Replace by `[chk_number](x); [chk_range](x)` #' #' @export chk_proportion <- function(x, x_name = NULL) { deprecate_warn("0.2.0", what = "chk::chk_proportion()", details = "Please use `chk_number(x)` or `chk_range(x)` instead" ) if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_number(x) chk_range(x) } #' @describeIn chk_deprecated Deparse Backtick #' #' `r lifecycle::badge("deprecated")` #' #' Replace with [deparse_backtick_chk()] #' #' @export deparse_backtick <- function(x) { deprecate_warn("0.2.0", what = "chk::deparse_backtick()", with = "chk::deparse_backtick_chk()" ) deparse_backtick_chk(x) } chk/R/check-files.R0000644000176200001440000000215314436206156013530 0ustar liggesusers#' Check Files Exist #' #' @description #' Checks if all files exist (or if exists = FALSE do not exist as files or directories). #' #' @inheritParams params #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @examples #' check_files(tempfile("unlikely-that-exists-chk"), exists = FALSE) #' try(check_files(tempfile("unlikely-that-exists-chk"))) #' @export check_files <- function(x, exists = TRUE, x_name = NULL) { if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) chk_character(x, x_name = x_name) chk_vector(x, x_name = x_name) chk_not_any_na(x, x_name = x_name) chk_flag(exists) dirs <- vapply(x, vld_dir, TRUE) if (any(dirs)) { abort_chk(x_name, " must specify files ('", x[dirs][1], "' is a directory)", x = x) } x <- x[vapply(x, vld_file, TRUE) != exists] if (!length(x)) { return(invisible(x)) } x <- x[1] if (exists) { abort_chk(x_name, " must specify existing files ('", x, "' can't be found)", x = x) } abort_chk(x_name, " must not specify existing files ('", x, "' exists)", x = x) } chk/R/chk-compatible-lengths.R0000644000176200001440000000442014436206156015676 0ustar liggesusers#' Check Compatible Lengths #' #' Checks objects (including vectors) have lengths that could be 'strictly #' recycled'. That is to say they must all be either zero length or the same #' length with some of length 1. #' #' @inheritParams params #' @param ... The objects to check for compatible lengths. #' @return The `chk_` function throws an informative error if the test fails. #' @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 and #' length 4, even though the vector of length 2 could be 'loosely recycled' to #' match up to the vector of length 4 when combined. #' #' The intent of the function is to check that only strict recycling is #' occurring. #' #' @examples #' # chk_compatible_lengths #' #' a <- integer(0) #' b <- numeric(0) #' chk_compatible_lengths(a, b) #' #' a <- 1 #' b <- 2 #' chk_compatible_lengths(a, b) #' #' a <- 1:3 #' b <- 1:3 #' chk_compatible_lengths(a, b) #' #' b <- 1 #' chk_compatible_lengths(a, b) #' #' b <- 1:2 #' try(chk_compatible_lengths(a, b)) #' #' b <- 1:6 #' try(chk_compatible_lengths(a, b)) #' @export chk_compatible_lengths <- function(..., x_name = NULL) { if (vld_compatible_lengths(...)) { return(invisible()) } if (is.null(x_name)) { x_name <- "... objects" } chk_string(x_name) vec_lengths <- lengths(list(...)) length_set <- sort(unique(vec_lengths)) abort_chk( x_name, paste0( " must be all zero length or the same length with some of length of 1 ", "but not lengths " ), cc(length_set, conj = " and ") ) } #' @describeIn chk_compatible_lengths Validate Compatible Lengths #' @export #' @examples #' # vld_compatible_lengths #' #' a <- integer(0) #' b <- numeric(0) #' vld_compatible_lengths(a, b) #' #' a <- 1 #' b <- 2 #' vld_compatible_lengths(a, b) #' #' a <- 1:3 #' b <- 1:3 #' vld_compatible_lengths(a, b) #' #' b <- 1 #' vld_compatible_lengths(a, b) #' #' b <- 1:2 #' vld_compatible_lengths(a, b) #' #' b <- 1:6 #' vld_compatible_lengths(a, b) vld_compatible_lengths <- function(...) { vec_lengths <- lengths(list(...)) length_set <- unique(vec_lengths) if (length(length_set) <= 1) { return(TRUE) } if (length(length_set) >= 3) { return(FALSE) } min(length_set) == 1 } chk/R/chk-false.R0000644000176200001440000000136014436206156013207 0ustar liggesusers#' Check FALSE #' #' @description #' Check if FALSE using #' #' `is.logical(x) && length(x) == 1L && !anyNA(x) && !x` #' #' @inheritParams params #' @inherit params return #' #' @family chk_logical #' #' @examples #' # chk_false #' chk_false(FALSE) #' try(chk_false(0)) #' @export chk_false <- function(x, x_name = NULL) { if (vld_false(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be FALSE", x = x) } #' @describeIn chk_false Validate FALSE #' #' @examples #' # vld_false #' vld_false(TRUE) #' vld_false(FALSE) #' vld_false(NA) #' vld_false(0) #' vld_false(c(FALSE, FALSE)) #' @export vld_false <- function(x) is.logical(x) && length(x) == 1L && !anyNA(x) && !x chk/R/chk-datetime.R0000644000176200001440000000327414436206156013717 0ustar liggesusers#' Check Date Time #' #' @description #' Checks if non-missing POSIXct scalar using #' #' `inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_date_time #' chk_date_time(as.POSIXct("2001-01-02")) #' try(chk_date_time(1)) #' @export chk_date_time <- function(x, x_name = NULL) { if (vld_date_time(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a date time (non-missing POSIXct scalar)", x = x) } #' @describeIn chk_date_time Check Date Time (Deprecated) #' #' `r lifecycle::badge("deprecated")` #' #' @export chk_datetime <- function(x, x_name = NULL) { deprecate_warn("0.4.1", what = "chk::chk_datetime()", with = "chk::chk_date_time()", id = "chk_datetime" ) if (vld_date_time(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a date time (non-missing POSIXct scalar)", x = x) } #' @describeIn chk_date_time Validate Date Time #' #' @examples #' # vld_date_time #' vld_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())) #' @export vld_date_time <- function(x) { inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x) } #' @describeIn chk_date_time Validate Date Time (Deprecated) #' #' `r lifecycle::badge("deprecated")` #' #' @export vld_datetime <- function(x) { deprecate_warn("0.4.1", what = "chk::vld_datetime()", with = "chk::vld_date_time()", id = "chk_datetime" ) vld_date_time(x) } chk/R/chk-true.R0000644000176200001440000000133314436206156013074 0ustar liggesusers#' Check TRUE #' #' @description #' Checks if TRUE using #' #' `is.logical(x) && length(x) == 1L && !anyNA(x) && x` #' #' @inheritParams params #' @inherit params return #' #' @family chk_logical #' #' @examples #' # chk_true #' chk_true(TRUE) #' try(chk_true(1)) #' @export chk_true <- function(x, x_name = NULL) { if (vld_true(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be TRUE", x = x) } #' @describeIn chk_true Validate TRUE #' #' @examples #' # vld_true #' vld_true(TRUE) #' vld_true(FALSE) #' vld_true(NA) #' vld_true(0) #' vld_true(c(TRUE, TRUE)) #' @export vld_true <- function(x) is.logical(x) && length(x) == 1L && !anyNA(x) && x chk/R/chk-unique.R0000644000176200001440000000172114436206156013424 0ustar liggesusers#' Check Unique #' #' @description #' Checks if unique using #' #' `!anyDuplicated(x, incomparables = incomparables)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_unique #' chk_unique(c(NA, 2)) #' try(chk_unique(c(NA, NA, 2))) #' chk_unique(c(NA, NA, 2), incomparables = NA) #' @export chk_unique <- function(x, incomparables = FALSE, x_name = NULL) { if (vld_unique(x, incomparables = incomparables)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be unique", x = x, incomparables = incomparables) } #' @describeIn chk_unique Validate Unique #' #' @examples #' # vld_unique #' vld_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) #' @export vld_unique <- function(x, incomparables = FALSE) { !.anyDuplicated(x, incomparables = incomparables) } chk/R/chk-used.R0000644000176200001440000000131114436206156013051 0ustar liggesusers#' Check ... Used #' #' @description #' Checks if is ... used using #' #' `length(list(...)) != 0L` #' #' @inheritParams params #' @inherit params return #' @return The `chk_` function throws an informative error if the test fails. #' #' @family chk_ellipsis #' #' @examples #' # chk_used #' fun <- function(x, ...) { #' chk_used(...) #' x #' } #' try(fun(1)) #' fun(1, 2) #' @export chk_used <- function(...) { if (vld_used(...)) { return(invisible()) } abort_chk("`...` must be used") } #' @describeIn chk_used Validate ... Used #' #' @examples #' # vld_used #' fun <- function(x, ...) { #' vld_used(...) #' } #' fun(1) #' fun(1, 2) #' @export vld_used <- function(...) length(list(...)) != 0L chk/R/chk-wnum.R0000644000176200001440000000243314436206156013105 0ustar liggesusers#' 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))))` #' #' `r lifecycle::badge("deprecated")` #' #' @inheritParams params #' @inherit params return #' #' #' @family deprecated #' #' @examples #' # chk_wnum #' chk_wnum(1) #' try(chk_wnum(1.1)) #' @export chk_wnum <- function(x, x_name = NULL) { if (vld_wnum(x)) { return(invisible(x)) } deprecate_soft( "0.6.1", what = "chk::chk_wnum()", details = "Please use `chk::chk_scalar(x);` `chk::chk_whole_numeric(x)` instead", id = "chk_wnum" ) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be a whole numeric scalar", x = x) } #' @describeIn chk_wnum Validate Whole Numeric Scalar #' #' `r lifecycle::badge("deprecated")` #' #' @examples #' # vld_wnum #' vld_wnum(1) #' vld_wnum(double(0)) #' vld_wnum(NA_real_) #' vld_wnum(c(1, 1)) #' vld_wnum(1L) #' @export vld_wnum <- function(x) { deprecate_soft( "0.6.1", what = "chk::chk_wnum()", details = "Please use `chk::chk_scalar(x);` `chk::chk_whole_numeric(x)` instead", id = "chk_wnum" ) is.numeric(x) && length(x) == 1L && (is.integer(x) || vld_true(all.equal(x, trunc(x)))) } chk/R/chk-tz.R0000644000176200001440000000141414436206156012552 0ustar liggesusers#' Check Time Zone #' #' @description #' Checks if non-missing valid scalar timezone using #' #' `is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames()` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' chk_tz("UTC") #' try(chk_tz("TCU")) #' @export chk_tz <- function(x, x_name = NULL) { if (vld_tz(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a tz (non-missing scalar character of a recognized timezone)", x = x) } #' @describeIn chk_tz Validate Time Zone #' #' @examples #' vld_tz("UTC") #' vld_tz("TCU") #' @export vld_tz <- function(x) { is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames() } chk/R/check-values.R0000644000176200001440000000501014436206156013720 0ustar liggesusers#' Check Values and Class #' #' @description #' Checks values and S3 class of an atomic object. #' #' @details #' To check the class simply pass a vector of the desired class. #' #' To check that x does not include missing values pass #' a 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 pass #' a 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 values #' pass three or more non-missing values. #' #' In the case of a factor ensure values has two levels to #' check that the levels of x are an ordered superset of the levels of value #' and three or more levels to check that they are identical. #' #' @inheritParams params #' @param values An atomic vector specifying the S3 class and possible values. #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @examples #' check_values(1, numeric(0)) #' check_values(1, 2) #' try(check_values(1, 1L)) #' try(check_values(NA_real_, 1)) #' @export check_values <- function(x, values, x_name = NULL) { if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) chk_atomic(x, x_name = x_name) chk_vector(values) chk_atomic(values) class <- class(values)[1] chk_s3_class(x, class, x_name = x_name) if (is.factor(values) && nlevels(values) > 1) { x_name_levels <- backtick_chk(p0("levels(", unbacktick_chk(x_name), ")")) if (nlevels(values) > 2) { chk_identical(levels(x), levels(values), x_name = x_name_levels) } else { chk_superset(levels(x), levels(values), x_name = x_name_levels) chk_orderset(levels(x), levels(values), x_name = x_name_levels) } } if (!length(x) || !length(values)) { return(invisible(x)) } if (vld_not_any_na(values)) chk_not_any_na(x, x_name = x_name) x <- x[!is.na(x)] values <- values[!is.na(values)] if (!length(x) || length(values) < 2) { return(invisible(x)) } if (identical(length(values), 2L)) { values <- sort(unique(values)) if (identical(length(values), 1L)) { return(chk_all(x, chk_equal, values, x_name = x_name)) } if (is.factor(values) && (nlevels(values) < 3 || !is.ordered(values))) { return(invisible()) } return(chk_range(x, values, x_name = x_name)) } chk_subset(x, sort(unique(values)), x_name = x_name) } chk/R/chk-ext.R0000644000176200001440000000166114436206156012721 0ustar liggesusers#' Check File Extension #' #' @description #' Checks extension using #' #' `vld_string(x) && vld_subset(tools::file_ext(x), ext)` #' #' The user may want to use [toupper()] or [tolower()] #' to ensure the case matches. #' #' @inheritParams params #' @inherit params return #' #' @family chk_files #' #' @examples #' # chk_ext #' try(chk_ext("file1.pdf", "png")) #' @export chk_ext <- function(x, ext, x_name = NULL) { if (vld_ext(x, ext)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_string(x, x_name = x_name) abort_chk( x_name, " must have extension ", cc(ext, " or "), " (not '", tools::file_ext(x), "')", x = x, ext = ext ) } #' @describeIn chk_ext Validate File Extension #' #' @examples #' # vld_ext #' vld_ext("oeu.pdf", "pdf") #' vld_ext(toupper("oeu.pdf"), "PDF") #' @export vld_ext <- function(x, ext) vld_string(x) && vld_subset(tools::file_ext(x), ext) chk/R/check-names.R0000644000176200001440000000325314436206156013533 0ustar liggesusers#' Check Names #' #' @description #' Checks the names of an object. #' #' @inheritParams params #' @param names A character vector of the required names. #' @param exclusive A flag specifying whether x must only contain the required names. #' @param order A flag specifying whether the order of the required names in x must match the order in names. #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @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)) #' @export check_names <- function(x, names = character(0), exclusive = FALSE, order = FALSE, x_name = NULL) { chk_s3_class(names, "character") chk_unique(names) chk_not_any_na(names) chk_flag(exclusive) chk_flag(order) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) chk_named(x, x_name = x_name) x_names <- names(x) if (!length(names)) { if (exclusive && length(x_names)) { abort_chk(x_name, " must not have any elements") } return(invisible(x)) } x_name <- backtick_chk(p0("names(", unbacktick_chk(x_name), ")")) if (length(setdiff(names, x_names))) { abort_chk(x_name, " must include ", cc(setdiff(names, x_names), conj = " and ")) } if (exclusive && length(setdiff(x_names, names))) { abort_chk(x_name, " must not include ", cc(setdiff(x_names, names), conj = " or ")) } if (order && !identical(intersect(names, x_names), intersect(x_names, names))) { abort_chk(x_name, " must include ", cc(names, conj = " and "), " in that order") } invisible(x) } chk/R/chk-scalar.R0000644000176200001440000000120714436206156013362 0ustar liggesusers#' Check Scalar #' #' @description #' Checks if is a vector using #' #' `length(x) == 1L` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_scalar #' chk_scalar(1) #' chk_scalar(list(1)) #' try(chk_scalar(1:2)) #' @export chk_scalar <- function(x, x_name = NULL) { if (vld_scalar(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a scalar (length 1)", x = x) } #' @describeIn chk_scalar Validate Scalar #' #' @examples #' # vld_scalar #' vld_scalar(1) #' @export vld_scalar <- function(x) length(x) == 1L chk/R/chk-numeric.R0000644000176200001440000000151114436206156013555 0ustar liggesusers#' 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`. #' #' @inheritParams chk_flag #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_numeric #' chk_numeric(1) #' try(chk_numeric("1")) #' @export chk_numeric <- function(x, x_name = NULL) { if (vld_numeric(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be numeric", x = x) } #' @describeIn chk_numeric Validate Numeric #' #' @examples #' # vld_numeric #' vld_numeric(1) #' vld_numeric(1:2) #' vld_numeric(NA_real_) #' vld_numeric(integer(0)) #' vld_numeric("1") #' vld_numeric(TRUE) #' @export vld_numeric <- function(x) is.numeric(x) chk/R/chk-chr.R0000644000176200001440000000223014436206156012666 0ustar liggesusers#' Check Character Scalar #' #' @description #' Checks if character scalar using #' #' `is.character(x) && length(x) == 1L` #' #' `r lifecycle::badge("deprecated")` #' #' @family deprecated #' #' @inheritParams params #' @inherit params return #' #' @family chk_character #' #' @examples #' chk_chr("a") #' try(chk_chr(1)) #' @export chk_chr <- function(x, x_name = NULL) { if (vld_chr(x)) { return(invisible(x)) } deprecate_soft( "0.6.1", what = "chk::chk_chr()", details = "Please use `chk::chk_scalar(x);` `chk::chk_character(x)` instead", id = "chk_chr" ) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be a character scalar", x = x) } #' @describeIn chk_chr Validate Character Scalar #' #' `r lifecycle::badge("deprecated")` #' #' @examples #' # vld_chr #' vld_chr("") #' vld_chr("a") #' vld_chr(NA_character_) #' vld_chr(c("a", "b")) #' vld_chr(1) #' @export vld_chr <- function(x) { deprecate_soft( "0.6.1", what = "chk::chk_chr()", details = "Please use `chk::chk_scalar(x);` `chk::chk_character(x)` instead", id = "chk_chr" ) is.character(x) && length(x) == 1L } chk/R/aaa.R0000644000176200001440000000055514436206156012101 0ustar liggesusers#' Workaround: Avoid backtraces in examples #' #' This example will run first and set the option for the process that builds #' the example. #' (By default, pkgdown builds in a separate process.) #' This also produces a help page that isn't linked from anywhere. #' #' @name aaa #' @keywords internal #' @examples #' options(rlang_backtrace_on_error = "none") NULL chk/R/chkor-vld.R0000644000176200001440000000337714506146212013247 0ustar liggesuserstry_chk <- function(quo) { catch_cnd(eval_tidy(quo), classes = "error") } try_msg <- function(x) { # FIXME: Tests fail when the code below is changed to conditionMessage(x) # because rlang implements conditionMessage.rlang_error() . # Does that output look satisfactory? conditionMessage.condition(x) } chkor_quos <- function(quos) { n <- length(quos) if (n == 0L) { return(invisible()) } msg <- character(n) for (i in seq_len(n)) { try <- try_chk(quos[[i]]) if (is.null(try)) { return(invisible()) } msg[[i]] <- try_msg(try) } msg <- unique(msg) if (length(msg) > 1) { msg <- p0(msg, collapse = "\n* ") msg <- p0("At least one of the following conditions must be met:\n* ", msg) } abort_chk(msg) } vld__to_chk_ <- function(quo) { str <- deparse(quo) str <- sub("^vld_", "chk_", str) str2lang(str) } #' Chk OR #' #' @param ... Multiple `vld_` calls. #' #' A common mistake is to pass `chk_` calls. #' #' `chkor_vld()` is relatively slow. #' If at all possible use [chk_null_or()] or first test using the individual #' `vld_` functions and then call `chkor_vld()` to generate an informative #' error message. #' #' @return An informative error if the test fails. #' #' @seealso [chk_null_or()] #' #' @export #' #' @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)) chkor_vld <- function(...) { quos <- enquos(...) n <- length(quos) if (n == 0L) { return(invisible()) } for (quo in quos) { if (eval_tidy(quo)) { return(invisible()) } } for (i in seq_len(n)) { quos[[i]] <- quo_set_expr(quos[[i]], vld__to_chk_(quo_get_expr(quos[[i]]))) } chkor_quos(quos) } chk/R/chk-sorted.R0000644000176200001440000000122014436206156013410 0ustar liggesusers#' Check Sorted #' #' @description #' Checks if is sorted using #' #' `is.unsorted(x, na.rm = TRUE)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_sorted #' chk_sorted(1:2) #' try(chk_sorted(2:1)) #' @export chk_sorted <- function(x, x_name = NULL) { if (vld_sorted(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be sorted", x = x) } #' @describeIn chk_sorted Validate Sorted #' #' @examples #' # vld_sorted #' vld_sorted(1:2) #' vld_sorted(2:1) #' @export vld_sorted <- function(x) !is.unsorted(x, na.rm = TRUE) chk/R/chk-lt.R0000644000176200001440000000173514436206156012542 0ustar liggesusers#' Check Less Than #' #' @description #' Checks if all non-missing values are less than value using #' #' `all(x[!is.na(x)] < value)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_ranges #' #' @examples #' # chk_lt #' chk_lt(-0.1) #' try(chk_lt(c(-0.1, 0.2))) #' @export chk_lt <- function(x, value = 0, x_name = NULL) { if (vld_lt(x, value)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk(x_name, " must be less than ", cc(value), ", not ", cc(x), x = x, value = value) } abort_chk(x_name, " must have values less than ", cc(value), x = x, value = value) } #' @describeIn chk_lt Validate Less Than #' #' @examples #' # vld_lt #' vld_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") #' @export vld_lt <- function(x, value = 0) all(x[!is.na(x)] < value) chk/R/chk-orderset.R0000644000176200001440000000233214436206156013744 0ustar liggesusers#' Check Set Ordered #' #' @description #' Checks if the first occurrence of each shared element #' in x is equivalent to the first occurrence of each shared element in values using #' `vld_equivalent(unique(x[x %in% values]), values[values %in% x])`. #' #' @inheritParams params #' @return #' The `chk_` function throws an informative error if the test fails. #' #' The `vld_` function returns a flag indicating whether the test was met. #' #' @family chk_set #' @export #' #' @examples #' #' # chk_orderset #' chk_orderset(1:2, 1:2) #' try(chk_orderset(2:1, 1:2)) chk_orderset <- function(x, values, x_name = NULL) { if (vld_orderset(x, values)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) values <- values[values %in% x] abort_chk(x_name, " must have (the first occurence of) each of the following elements in the following order: ", cc(values), x = x, values = values) } #' @describeIn chk_setequal Validate Set Ordered #' #' @export #' #' @examples #' #' # vld_orderset #' vld_orderset(1, 1) #' vld_orderset(1:2, 2:1) #' vld_orderset(1, 2:1) #' vld_orderset(1:2, 2) vld_orderset <- function(x, values) { vld_equivalent(unique(x[x %in% values]), values[values %in% x]) } chk/R/namespace.R0000644000176200001440000000004014436206156013300 0ustar liggesusers#' @import rlang lifecycle NULL chk/R/chk-all-equal.R0000644000176200001440000000203614436206156013773 0ustar liggesusers#' 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))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_alls #' #' @examples #' # chk_all_equal #' chk_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)))) #' @export chk_all_equal <- function(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL) { if (vld_all_equal(x, tolerance = tolerance)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must have equal elements", x = x, tolerance = tolerance) } #' @describeIn chk_all_equal Validate All Equal #' #' @examples #' # vld_all_equal #' vld_all_equal(c(1, 1L)) #' @export vld_all_equal <- function(x, tolerance = sqrt(.Machine$double.eps)) { length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance)) } chk/R/chk-null-or.R0000644000176200001440000000256714506142666013522 0ustar liggesusers#' Check NULL Or #' #' @description #' Checks if NULL or passes test. #' #' @inheritParams params #' @param chk A chk function. Soft-deprecated for vld. `r lifecycle::badge("deprecated")` #' @param vld A vld function. #' @param ... Arguments passed to chk. #' #' @return An informative error if the test fails. #' @export #' #' @examples #' chk_null_or(NULL, chk_number) #' chk_null_or(1, chk_number) #' try(chk_null_or("1", chk_number)) chk_null_or <- function(x, chk, ..., vld, x_name = NULL) { if (!missing(chk)) { lifecycle::deprecate_soft("0.6.1", "chk_null_or(chk)", "chk_null_or(vld)") } if (is.null(x)) { return(invisible(x)) } if (missing(vld)) { try <- try_chk(chk(x, ...)) if (is.null(try)) { return(invisible(x)) } if (is.null(x_name)) { x_name <- deparse_backtick_chk(substitute(x)) try <- try_chk(chk(x, ..., x_name = x_name)) } msg <- try_msg(try) msg <- sub("[.]$", " or NULL.", msg) abort_chk(msg, x = x) } if (vld(x, ...)) { return(invisible(x)) } if (is.null(x_name)) { x_name <- deparse_backtick_chk(substitute(x)) } chk <- deparse(substitute(vld)) chk <- sub("^(chk::){0,1}vld_", "chk_", chk) chk <- paste0(chk, "(x, ..., x_name = x_name)") chk <- parse(text = chk) try <- try_chk(eval(chk)) msg <- try_msg(try) msg <- sub("[.]$", " or NULL.", msg) abort_chk(msg, x = x) } chk/R/chk-file.R0000644000176200001440000000152414436206156013036 0ustar liggesusers#' Check File Exists #' #' @description #' Checks if file exists using #' #' `vld_string(x) && file.exists(x) && !dir.exists(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_files #' #' @examples #' # chk_file #' try(chk_file(tempfile())) #' @export chk_file <- function(x, x_name = NULL) { if (vld_file(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_string(x, x_name = x_name) if (dir.exists(x)) { abort_chk(x_name, " must specify a file ('", x, "' is a directory)", x = x) } abort_chk(x_name, " must specify an existing file ('", x, "' can't be found)", x = x) } #' @describeIn chk_file Validate File Exists #' #' @examples #' # vld_file #' vld_file(tempfile()) #' @export vld_file <- function(x) vld_string(x) && file.exists(x) && !dir.exists(x) chk/R/chk-logical.R0000644000176200001440000000134014436206156013525 0ustar liggesusers#' Check Logical #' #' @description #' Checks if logical using #' #' `is.logical(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_logical #' chk_logical(TRUE) #' try(chk_logical(1)) #' @export chk_logical <- function(x, x_name = NULL) { if (vld_logical(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be logical", x = x) } #' @describeIn chk_logical Validate Logical #' #' @examples #' # vld_logical #' vld_logical(TRUE) #' vld_logical(matrix(TRUE)) #' vld_logical(logical(0)) #' vld_logical(NA) #' vld_logical(1) #' vld_logical("TRUE") #' @export vld_logical <- function(x) is.logical(x) chk/R/chk-whole-number.R0000644000176200001440000000175114436206156014525 0ustar liggesusers#' 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)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_whole_number #' chk_whole_number(2) #' try(chk_whole_number(1.1)) #' @export chk_whole_number <- function(x, x_name = NULL) { if (vld_whole_number(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk( x_name, " must be a whole number (non-missing integer scalar or double equivalent)", x = x ) } #' @describeIn chk_whole_number Validate Whole Number #' #' @examples #' # vld_whole_number #' vld_whole_number(2) #' @export vld_whole_number <- function(x) { vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x)))) } chk/R/chk-join.R0000644000176200001440000000242714436206156013061 0ustar liggesusers#' Check Join #' #' @description #' Checks if all rows in x match at least one in y. #' #' @inheritParams params #' @param y A data.frame with columns in by. #' @inherit params return #' #' @family chk_set #' #' @examples #' # chk_join #' chk_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")) #' @export chk_join <- function(x, y, by, x_name = NULL) { if (vld_join(x, y, by)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) y_name <- as_label(y) obj_of <- if (grepl("^<", y_name)) "the y object of class " else NULL abort_chk("All rows in ", x_name, " must match at least one in ", obj_of, y_name, x = x, y = y, by = by ) } #' @describeIn chk_join Validate Join #' #' @examples #' # vld_join #' vld_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")) #' @export vld_join <- function(x, y, by) { identical( nrow(x), nrow(merge(as.data.frame(x), unique(as.data.frame(y)[by]), by.x = if (is.null(names(by))) by else names(by), by.y = by )) ) } chk/R/cc.R0000644000176200001440000000276314436206156011747 0ustar liggesusers#' Concatenate with Commas #' #' Concatenates object values into a string with each value separated by a comma #' and the last value separated by a conjunction. #' #' By default, if x has more than 10 values an ellipsis is used #' to ensure only 10 values are displayed (including the ellipsis). #' #' @param x The object to concatenate. #' @param conj A string of the conjunction to separate the last value by. #' @param sep A string of the separator. #' @param brac A string to brac the values by. #' @param ellipsis A numeric scalar of the maximum number of values to display #' before using an ellipsis. #' @param chk A flag specifying whether to check the other parameters. #' #' @return A string. #' @export #' #' @examples #' cc(1:2) #' cc(1:2, conj = " or") #' cc(3:1, brac = "'") #' cc(1:11) #' cc(as.character(1:2)) cc <- function(x, conj = ", ", sep = ", ", brac = if (is.character(x) || is.factor(x)) "'" else "", ellipsis = 10L, chk = TRUE) { if (chk) { chk_string(conj) chk_string(sep) chk_s3_class(brac, "character") chk_range(length(brac), 1:2) chk_whole_number(ellipsis) chk_gte(ellipsis, 3) } if (!length(x)) { return(character(0)) } x <- p0(brac[1], x, brac[length(brac)]) n <- length(x) if (n == 1L) { return(x) } if (n == 2L) { return(p(x, collapse = conj)) } if (n > ellipsis) { x <- c(x[1:(ellipsis - 2)], "...", x[n]) n <- ellipsis } p(c(p0(x[1:(n - 1)], collapse = sep), x[n]), collapse = conj) } chk/R/chk-gte.R0000644000176200001440000000201514436206156012672 0ustar liggesusers#' 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)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_ranges #' #' @examples #' # chk_gte #' chk_gte(0) #' try(chk_gte(-0.1)) #' @export chk_gte <- function(x, value = 0, x_name = NULL) { if (vld_gte(x, value)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk( x_name, " must be greater than or equal to ", cc(value), ", not ", cc(x), x = x, value = value ) } abort_chk(x_name, " must have values greater than or equal to ", cc(value), x = x, value = value) } #' @describeIn chk_gte Validate Greater Than or Equal To #' #' @examples #' # vld_gte #' vld_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) #' @export vld_gte <- function(x, value = 0) all(x[!is.na(x)] >= value) chk/R/chk-lte.R0000644000176200001440000000175114436206156012705 0ustar liggesusers#' 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)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_ranges #' #' @examples #' # chk_lte #' chk_lte(0) #' try(chk_lte(0.1)) #' @export chk_lte <- function(x, value = 0, x_name = NULL) { if (vld_lte(x, value)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk( x_name, " must be less than or equal to ", cc(value), ", not ", cc(x), "" ) } abort_chk(x_name, " must have values less than or equal to ", cc(value), x = x, value = value) } #' @describeIn chk_lte Validate Less Than or Equal To #' #' @examples #' # vld_lte #' vld_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) #' @export vld_lte <- function(x, value = 0) all(x[!is.na(x)] <= value) chk/R/chk-number.R0000644000176200001440000000145614436206156013413 0ustar liggesusers#' 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_` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_number #' chk_number(1.1) #' try(chk_number(TRUE)) #' @export chk_number <- function(x, x_name = NULL) { if (vld_number(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a number (non-missing numeric scalar)", x = x) } #' @describeIn chk_number Validate Number #' #' @examples #' # vld_number #' vld_number(1.1) #' @export vld_number <- function(x) { is.numeric(x) && length(x) == 1L && !anyNA(x) } chk/R/chk-environment.R0000644000176200001440000000141314436206156014460 0ustar liggesusers#' Check Environment #' #' @description #' Checks if environment using #' #' `is.environment(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_environment #' chk_environment(.GlobalEnv) #' try(chk_environment(1)) #' @export chk_environment <- function(x, x_name = NULL) { if (vld_environment(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be an environment", x = x) } #' @describeIn chk_environment Validate Environment #' #' @examples #' # vld_environment #' vld_environment(1) #' vld_environment(list(1)) #' vld_environment(.GlobalEnv) #' vld_environment(environment()) #' @export vld_environment <- function(x) is.environment(x) chk/R/chk-package.R0000644000176200001440000000031214436206156013504 0ustar liggesusers#' @keywords internal "_PACKAGE" # The following block is used by usethis to automatically manage # roxygen namespace tags. Modify with care! ## usethis namespace: start ## usethis namespace: end NULL chk/R/chk-count.R0000644000176200001440000000137514436206156013253 0ustar liggesusers#' Check Count #' #' @description #' Checks if non-negative whole number using #' #' `vld_whole_number(x) && x >= 0` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_count #' chk_count(1) #' try(chk_count(1.5)) #' @export chk_count <- function(x, x_name = NULL) { if (vld_count(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be a count (non-negative non-missing integer scalar or double equivalent)", x = x) } #' @describeIn chk_count Validate Count #' #' @examples #' # vld_count #' vld_count(1) #' vld_count(0L) #' vld_count(-1) #' vld_count(0.5) #' @export vld_count <- function(x) { vld_whole_number(x) && x >= 0 } chk/R/chk-all-identical.R0000644000176200001440000000164314436206156014623 0ustar liggesusers#' 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)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_alls #' #' @examples #' # chk_all_identical #' chk_all_identical(c(1, 1)) #' try(chk_all_identical(c(1, 1.1))) #' @export chk_all_identical <- function(x, x_name = NULL) { if (vld_all_identical(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must have identical elements", x = x) } #' @describeIn chk_all_identical Validate All Identical #' #' @examples #' # vld_all_identical #' vld_all_identical(c(1, 1)) #' @export vld_all_identical <- function(x) { length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]])) } chk/R/chk-equivalent.R0000644000176200001440000000217214436206156014274 0ustar liggesusers#' Check Equivalent #' #' @description #' Checks if is equivalent (equal ignoring attributes) to y using #' #' `vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_equals #' #' @examples #' # chk_equivalent #' chk_equivalent(1, 1.00000001) #' try(chk_equivalent(1, 1.0000001)) #' chk_equivalent(1, 1L) #' chk_equivalent(c(x = 1), c(y = 1)) #' @export chk_equivalent <- function(x, y, tolerance = sqrt(.Machine$double.eps), x_name = NULL) { if (vld_equivalent(x, y, tolerance = tolerance)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) y_name <- as_label(y) obj_of <- if (grepl("^<", y_name)) "the y object of class " else NULL abort_chk(x_name, " must be equivalent to ", obj_of, y_name, x = x, y = y ) } #' @describeIn chk_equivalent Validate Equivalent #' #' @examples #' vld_equivalent(c(x = 1), c(y = 1L)) #' @export vld_equivalent <- function(x, y, tolerance = sqrt(.Machine$double.eps)) { vld_true(all.equal(x, y, tolerance, check.attributes = FALSE)) } chk/R/chk-s4-class.R0000644000176200001440000000164114436206156013550 0ustar liggesusers#' Check Inherits from S4 Class #' #' @description #' Checks inherits from S4 class using #' #' `isS4(x) && methods::is(x, class)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_s4_class #' try(chk_s4_class(1, "numeric")) #' chk_s4_class(getClass("MethodDefinition"), "classRepresentation") #' @export chk_s4_class <- function(x, class, x_name = NULL) { if (vld_s4_class(x, class)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) .class <- class abort_chk(x_name, " must inherit from S4 class '", .class, "'", x = x, .class = .class) } #' @describeIn chk_s4_class Validate Inherits from S4 Class #' #' @examples #' # vld_s4_class #' vld_s4_class(numeric(0), "numeric") #' vld_s4_class(getClass("MethodDefinition"), "classRepresentation") #' @export vld_s4_class <- function(x, class) isS4(x) && methods::is(x, class) chk/R/chk-matrix.R0000644000176200001440000000120114436206156013413 0ustar liggesusers#' Check Matrix #' #' @description #' Checks if is a matrix using #' #' `is.matrix(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_matrix #' chk_matrix(matrix(1)) #' try(chk_matrix(array(1))) #' @export chk_matrix <- function(x, x_name = NULL) { if (vld_matrix(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be an matrix", x = x) } #' @describeIn chk_matrix Validate Matrix #' #' @examples #' # vld_matrix #' vld_matrix(1) #' vld_matrix(matrix(1)) #' @export vld_matrix <- function(x) is.matrix(x) chk/R/check-dirs.R0000644000176200001440000000211314436206156013363 0ustar liggesusers#' Check Directories Exist #' #' @description #' Checks if all directories exist (or if exists = FALSE do not exist as directories or files). #' #' @inheritParams params #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @examples #' check_dirs(tempdir()) #' try(check_dirs(tempdir(), exists = FALSE)) #' @export check_dirs <- function(x, exists = TRUE, x_name = NULL) { if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) chk_character(x, x_name = x_name) chk_vector(x, x_name = x_name) chk_not_any_na(x, x_name = x_name) chk_flag(exists) dirs <- vapply(x, vld_file, TRUE) if (any(dirs)) { abort_chk(x_name, " must specify directories ('", x[dirs][1], "' is a file)", x = x) } x <- x[vapply(x, vld_dir, TRUE) != exists] if (!length(x)) { return(invisible(x)) } x <- x[1] if (exists) { abort_chk(x_name, " must specify existing directories ('", x, "' can't be found)", x = x) } abort_chk(x_name, " must not specify existing directories ('", x, "' exists)", x = x) } chk/R/chk-not-any-na.R0000644000176200001440000000161614436206156014102 0ustar liggesusers#' 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)`. #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_not_any_na #' chk_not_any_na(1) #' try(chk_not_any_na(NA)) #' @export chk_not_any_na <- function(x, x_name = NULL) { if (vld_not_any_na(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must not have any missing values", x = x) } #' @describeIn chk_not_any_na Validate Not Any Missing Values #' #' @examples #' # vld_not_any_na #' vld_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) #' @export vld_not_any_na <- function(x) !anyNA(x) chk/R/chk-character-or-factor.R0000644000176200001440000000205514436206156015745 0ustar liggesusers#' Check Character or Factor #' #' @description #' Checks if character or factor using #' #' `is.character(x) || is.factor(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_character_or_factor #' chk_character_or_factor("1") #' chk_character_or_factor(factor("1")) #' try(chk_character(1)) #' @export chk_character_or_factor <- function(x, x_name = NULL) { if (vld_character_or_factor(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be character or factor", x = x) } #' @describeIn chk_character_or_factor Validate Character or Factor #' #' @examples #' # vld_character_or_factor #' vld_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")) #' @export vld_character_or_factor <- function(x) is.character(x) || is.factor(x) chk/R/chk-function.R0000644000176200001440000000200614436206156013740 0ustar liggesusers#' Check Function #' #' @description #' Checks if is a function using #' #' `is.function(x) && (is.null(formals) || length(formals(x)) == formals)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_function #' chk_function(mean) #' try(chk_function(1)) #' @export chk_function <- function(x, formals = NULL, x_name = NULL) { if (vld_function(x, formals)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (!is.function(x)) abort_chk(x_name, " must be a function", x = x, formals = formals) abort_chk(x_name, " must have ", formals, " formal arguments (not ", length(formals(x)), ")", x = x, formals = formals) } #' @describeIn chk_function Validate Function #' #' @examples #' # vld_function #' vld_function(mean) #' vld_function(function(x) x) #' vld_function(1) #' vld_function(list(1)) #' @export vld_function <- function(x, formals = NULL) { is.function(x) && (is.null(formals) || length(formals(x)) == formals) } chk/R/chk-dir.R0000644000176200001440000000156514436206156012702 0ustar liggesusers#' Check Directory Exists #' #' @description #' Checks if directory exists using #' #' `vld_string(x) && dir.exists(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_files #' #' @examples #' # chk_dir #' chk_dir(tempdir()) #' try(chk_dir(tempfile())) #' @export chk_dir <- function(x, x_name = NULL) { if (vld_dir(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) chk_string(x, x_name = x_name) if (file.exists(x)) { abort_chk(x_name, " must specify a directory ('", x, "' is a file)", x = x) } abort_chk(x_name, " must specify an existing directory ('", x, "' can't be found)", x = x) } #' @describeIn chk_dir Validate Directory Exists #' #' @examples #' # vld_dir #' vld_dir(1) #' vld_dir(tempdir()) #' vld_dir(tempfile()) #' @export vld_dir <- function(x) vld_string(x) && dir.exists(x) chk/R/chk-missing.R0000644000176200001440000000146314436206156013572 0ustar liggesusers#' Check Missing Argument #' #' @description #' Checks argument missing using #' #' `missing(x)` #' #' @details #' Currently only checks if value is available #' (as opposed to whether it was specified). #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_missing #' fun <- function(x) { #' chk_missing(x) #' } #' fun() #' try(fun(1)) #' @export chk_missing <- function(x, x_name = NULL) { if (vld_missing(x)) { return(invisible(NULL)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be missing") } #' @describeIn chk_missing Validate Missing Argument #' #' @examples #' # vld_missing #' fun <- function(x) { #' vld_missing(x) #' } #' fun() #' fun(1) #' @export vld_missing <- function(x) { missing(x) } chk/R/chk-unused.R0000644000176200001440000000134314436206156013421 0ustar liggesusers#' Check ... Unused #' #' @description #' Checks if ... is unused #' #' `length(list(...)) == 0L` #' #' @inheritParams params #' @inherit params return #' @return The `chk_` function throws an informative error if the test fails. #' #' @family chk_ellipsis #' #' @examples #' # chk_unused #' fun <- function(x, ...) { #' chk_unused(...) #' x #' } #' fun(1) #' try(fun(1, 2)) #' @export chk_unused <- function(...) { if (!length(list(...))) { return(invisible()) } abort_chk("`...` must be unused") } #' @describeIn chk_unused Validate ... Unused #' #' @examples #' # vld_unused #' fun <- function(x, ...) { #' vld_unused(...) #' } #' fun(1) #' try(fun(1, 2)) #' @export vld_unused <- function(...) length(list(...)) == 0L chk/R/chk-atomic.R0000644000176200001440000000127314506137265013376 0ustar liggesusers#' Check Atomic #' #' @description #' Checks if atomic using #' #' `is.atomic(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_atomic #' chk_atomic(1) #' try(chk_atomic(list(1))) #' @export chk_atomic <- function(x, x_name = NULL) { if (vld_atomic(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be atomic", x = x) } #' @describeIn chk_atomic Validate Atomic #' #' @examples #' # vld_atomic #' vld_atomic(1) #' vld_atomic(matrix(1:3)) #' vld_atomic(character(0)) #' vld_atomic(list(1)) #' vld_atomic(NULL) #' @export vld_atomic <- function(x) is.atomic(x) chk/R/chk-double.R0000644000176200001440000000137114436206156013371 0ustar liggesusers#' Check Double #' #' @description #' Checks if double using #' #' `is.double(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_double #' chk_double(1) #' try(chk_double(1L)) #' @export chk_double <- function(x, x_name = NULL) { if (vld_double(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be double", x = x) } #' @describeIn chk_double Validate Double #' #' @examples #' # vld_double #' vld_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) #' @export vld_double <- function(x) is.double(x) chk/R/check-dim.R0000644000176200001440000000315414507602305013174 0ustar liggesusers#' Check Dimension #' #' @description #' Checks dimension of an object. #' #' @inheritParams params #' @param dim A function returning a non-negative whole number of the dimension. #' @param values A flag or a whole numeric vector of the value, value range or possible values. #' @param dim_name A string of the name of the dim function. #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @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))) #' @export check_dim <- function(x, dim = length, values = numeric(0), x_name = NULL, dim_name = NULL) { chk_function(dim) if (!vld_flag(values) && !vld_whole_numeric(values)) { chkor_vld(vld_flag(values), vld_whole_numeric(values)) } chk_whole_number(dim(x)) chk_gte(dim(x)) if (is.null(x_name)) x_name <- deparse((substitute(x))) chk_string(x_name) if (is.null(dim_name)) dim_name <- deparse((substitute(dim))) chk_string(dim_name) x_name <- backtick_chk(p0(dim_name, "(", x_name, ")")) if (!length(values)) { return(invisible(x)) } if (vld_true(values)) { return(chk_gt(dim(x), x_name = x_name)) } if (vld_false(values)) values <- 0L if (identical(length(values), 2L)) { if (!identical(values[1], values[2])) { return(chk_range(dim(x), sort(values), x_name = x_name)) } values <- unique(values) } if (identical(length(values), 1L)) { return(chk_equal(dim(x), values, x_name = x_name)) } chk_subset(dim(x), sort(unique(values)), x_name = x_name) } chk/R/chk-list.R0000644000176200001440000000122714436206156013072 0ustar liggesusers#' Check List #' #' @description #' Checks if is a list using #' #' `is.list(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_list #' chk_list(list()) #' try(chk_list(1)) #' @export chk_list <- function(x, x_name = NULL) { if (vld_list(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a list", x = x) } #' @describeIn chk_list Validate List #' #' @examples #' # vld_list #' vld_list(list()) #' vld_list(list(x = 1)) #' vld_list(mtcars) #' vld_list(1) #' vld_list(NULL) #' @export vld_list <- function(x) is.list(x) chk/R/chk-superset.R0000644000176200001440000000154214436206156013771 0ustar liggesusers#' Check Superset #' #' @description #' Checks if includes all values using #' #' `all(values %in% x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_set #' #' @examples #' # chk_superset #' chk_superset(1:3, 1) #' try(chk_superset(1:3, 4)) #' @export chk_superset <- function(x, values, x_name = NULL) { if (vld_superset(x, values)) { return(invisible(x)) } values <- sort(unique(values), na.last = TRUE) if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) values <- values[!values %in% x] abort_chk(x_name, " must include ", cc(values, " and "), x = x, values = values) } #' @describeIn chk_superset Validates Superset #' #' @examples #' # vld_superset #' vld_superset(1:3, 1) #' vld_superset(1:3, 4) #' vld_superset(integer(0), integer(0)) #' @export vld_superset <- function(x, values) all(values %in% x) chk/R/chk-data.R0000644000176200001440000000125414436206156013030 0ustar liggesusers#' Check Data #' #' @description #' Checks data.frame using #' #' `inherits(x, "data.frame")` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_data #' chk_data(data.frame(x = 1)) #' try(chk_data(1)) #' @export chk_data <- function(x, x_name = NULL) { if (vld_data(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a data.frame", x = x) } #' @describeIn chk_data Validate Data #' #' @examples #' # vld_data #' vld_data(data.frame()) #' vld_data(data.frame(x = 1)) #' vld_data(c(x = 1)) #' @export vld_data <- function(x) inherits(x, "data.frame") chk/R/chk-factor.R0000644000176200001440000000125314436206156013374 0ustar liggesusers#' Check Factor #' #' @description #' Checks if factor using #' #' `is.factor(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_factor #' chk_factor(factor("1")) #' try(chk_factor("1")) #' @export chk_factor <- function(x, x_name = NULL) { if (vld_factor(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be factor", x = x) } #' @describeIn chk_factor Validate Factor #' #' @examples #' # vld_factor #' vld_factor(factor("1")) #' vld_factor(factor(0)) #' vld_factor("1") #' vld_factor(1L) #' @export vld_factor <- function(x) is.factor(x) chk/R/chk-all-equivalent.R0000644000176200001440000000216414436206156015043 0ustar liggesusers#' 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))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_alls #' #' @examples #' # chk_all_equivalent #' chk_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))) #' @export chk_all_equivalent <- function(x, tolerance = sqrt(.Machine$double.eps), x_name = NULL) { if (vld_all_equivalent(x, tolerance = tolerance)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must have equivalent elements", x = x, tolerance = tolerance) } #' @describeIn chk_all_equivalent Validate All Equivalent #' #' @examples #' # vld_all_equivalent #' vld_all_equivalent(c(x = 1, y = 1)) #' @export vld_all_equivalent <- function(x, tolerance = sqrt(.Machine$double.eps)) { length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance)) } chk/R/chk-is.R0000644000176200001440000000133614436206156012533 0ustar liggesusers#' Check Class #' #' @description #' Checks inherits from class using #' #' `inherits(x, class)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' chk_is(1, "numeric") #' try(chk_is(1L, "double")) #' @export chk_is <- function(x, class, x_name = NULL) { if (vld_is(x, class)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) .class <- class abort_chk(x_name, " must inherit from class '", .class, "'", x = x, .class = .class) } #' @describeIn chk_is Validate Inherits from Class #' #' @examples #' #' # vld_is #' vld_is(numeric(0), "numeric") #' vld_is(1L, "double") #' @export vld_is <- function(x, class) { inherits(x, class) } chk/R/chk-null.R0000644000176200001440000000111314436206156013063 0ustar liggesusers#' Check NULL #' #' @description #' Checks if NULL using #' #' `is.null(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_nulls #' #' @examples #' # chk_null #' try(chk_null(1)) #' chk_null(NULL) #' @export chk_null <- function(x, x_name = NULL) { if (vld_null(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be NULL", x = x) } #' @describeIn chk_null Validate NULL #' #' @examples #' # vld_null #' vld_null(NULL) #' vld_null(1) #' @export vld_null <- function(x) is.null(x) chk/R/chk-subset.R0000644000176200001440000000166114436206156013426 0ustar liggesusers#' Check Subset #' #' @description #' Checks if all values in values using #' #' `all(x %in% values)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_set #' #' @examples #' # chk_subset #' chk_subset(1, 1:10) #' try(chk_subset(11, 1:10)) #' @export chk_subset <- function(x, values, x_name = NULL) { if (vld_subset(x, values)) { return(invisible(x)) } values <- sort(unique(values), na.last = TRUE) if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk(x_name, " must match ", cc(values, " or "), ", not ", cc(x), x = x, values = values) } abort_chk(x_name, " must have values matching ", cc(values, " or "), x = x, values = values) } #' @describeIn chk_subset Validate Subset #' #' @examples #' # vld_subset #' vld_subset(numeric(0), 1:10) #' vld_subset(1, 1:10) #' vld_subset(11, 1:10) #' @export vld_subset <- function(x, values) all(x %in% values) chk/R/chk-lgl.R0000644000176200001440000000135014436206156012672 0ustar liggesusers#' Check Logical Scalar #' #' @description #' Checks if logical scalar using #' #' `is.logical(x) && length(x) == 1L` #' #' @inheritParams params #' @inherit params return #' #' @family chk_logical #' #' @examples #' # chk_lgl #' chk_lgl(NA) #' try(chk_lgl(1)) #' @export chk_lgl <- function(x, x_name = NULL) { if (vld_lgl(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be a logical scalar (TRUE, FALSE or NA)", x = x) } #' @describeIn chk_lgl Validate Logical Scalar #' #' @examples #' # vld_lgl #' vld_lgl(TRUE) #' vld_lgl(FALSE) #' vld_lgl(NA) #' vld_lgl(1) #' vld_lgl(c(TRUE, TRUE)) #' @export vld_lgl <- function(x) is.logical(x) && length(x) == 1L chk/R/chk-dbl.R0000644000176200001440000000215314436206156012657 0ustar liggesusers#' Check Double Scalar #' #' @description #' Checks if double scalar using #' #' `is.double(x) && length(x) == 1L` #' #' `r lifecycle::badge("deprecated")` #' #' @inheritParams params #' @inherit params return #' #' @family deprecated #' #' @examples #' # chk_dbl #' chk_dbl(1) #' try(chk_dbl(1L)) #' @export chk_dbl <- function(x, x_name = NULL) { if (vld_dbl(x)) { return(invisible(x)) } deprecate_soft( "0.6.1", what = "chk::chk_dbl()", details = "Please use `chk::chk_scalar(x);` `chk::chk_double(x)` instead", id = "chk_dbl" ) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be double (real) scalar", x = x) } #' @describeIn chk_dbl Validate Double #' #' `r lifecycle::badge("deprecated")` #' #' @examples #' # vld_dbl #' vld_dbl(1) #' vld_dbl(double(0)) #' vld_dbl(NA_real_) #' vld_dbl(c(1, 1)) #' vld_dbl(1L) #' @export vld_dbl <- function(x) { deprecate_soft( "0.6.1", what = "chk::chk_dbl()", details = "Please use `chk::chk_scalar(x);` `chk::chk_double(x)` instead", id = "chk_dbl" ) is.double(x) && length(x) == 1L } chk/R/chk-setequal.R0000644000176200001440000000141514436206156013741 0ustar liggesusers#' Check Set Equal #' #' @description #' Checks if equal set using #' #' `setequal(x, values)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_set #' #' @examples #' # chk_setequal #' chk_setequal(1:2, 2:1) #' try(chk_setequal(1, 1:2)) #' @export chk_setequal <- function(x, values, x_name = NULL) { if (vld_setequal(x, values)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must equal set: ", cc(values), x = x, values = values) } #' @describeIn chk_setequal Validate Set Equal #' #' @examples #' # vld_setequal #' vld_setequal(1, 1) #' vld_setequal(1:2, 2:1) #' vld_setequal(1, 2:1) #' vld_setequal(1:2, 2) #' @export vld_setequal <- function(x, values) setequal(x, values) chk/R/new-duplicated.R0000644000176200001440000000461614436206156014266 0ustar liggesusers# from https://stevenmortimer.com/the-unfinished-duplicated-function/ new_duplicated <- function(x, incomparables = FALSE, fromLast = FALSE, ...) { if (!identical(incomparables, FALSE)) { n <- ncol(x) nmx <- names(x) nmincomparables <- names(incomparables) lincomparables <- length(incomparables) if (is.null(nmincomparables)) { if (lincomparables < n) { # pad any incomparables lists with the default value if list is shorter than the number columns in the supplied data.frame tmp <- c(incomparables, as.list(rep_len(FALSE, n - lincomparables))) names(tmp) <- nmx incomparables <- tmp } if (lincomparables > n) { # if the list is unnamed and there are more elements in the list than there are columns, then only first n elements warning(paste("more columns in 'incomparables' than x, only using the first", n, "elements")) incomparables <- incomparables[1:n] } } else { # for named lists, find match, else default value tmp <- as.list(rep_len(FALSE, n)) names(tmp) <- nmx i <- match(nmincomparables, nmx, 0L) if (any(i <= 0L)) { warning("not all columns named in 'incomparables' exist") } tmp[i[i > 0L]] <- incomparables[i > 0L] incomparables <- tmp[nmx] } # first determine duplicates, then override when an incomparable value is found in a row since the existence of even 1 incomparable value in a row means it cannot be a duplicate res <- duplicated(do.call("paste", c(x, sep = "\r")), fromLast = fromLast) # for better performance only bother with the columns that have incomparable values not set to the default: !identical(x, FALSE) run_incomp_check <- sapply(incomparables, FUN = function(x) { !identical(x, FALSE) }) if (sum(run_incomp_check) > 0L) { incomp_check <- mapply(FUN = function(column, incomparables) { match(column, incomparables) }, x[run_incomp_check], incomparables[run_incomp_check]) # any rows with an incomparable match means, TRUE, it can override the duplicated result overwrite <- apply(data.frame(incomp_check), 1, function(x) { any(!is.na(x)) }) res[overwrite] <- FALSE } return(res) } else if (length(x) != 1L) { duplicated(do.call("paste", c(x, sep = "\r")), fromLast = fromLast) } else { duplicated(x[[1L]], fromLast = fromLast, ...) } } chk/R/check-data.R0000644000176200001440000000261514436206156013342 0ustar liggesusers#' Check Data #' #' @description #' Checks column names, values, number of rows and key for a data.frame. #' #' @inheritParams params #' @param values A uniquely named list of atomic vectors of the column values. #' @return An informative error if the test fails or an invisible copy of x. #' #' @family check #' #' @export #' @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_data <- function(x, values = NULL, exclusive = FALSE, order = FALSE, nrow = numeric(0), key = character(0), x_name = NULL) { chk_data(x, "data.frame") if (is.null(values)) values <- structure(list(), .Names = character(0)) chk_list(values) chk_named(values) chk_unique(names(values)) chk_all(values, chk_fun = chk_atomic) if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) chk_string(x_name) check_dim(x, dim = base::nrow, values = nrow, x_name = x_name, dim_name = "nrow" ) check_names(x, names = names(values), exclusive = exclusive, order = order, x_name = x_name ) lapply(names(values), function(name) { check_values(x[[name]], values[[name]], x_name = backtick_chk(p0(unbacktick_chk(x_name), "$", name)) ) }) check_key(x, key = key, x_name = x_name) invisible(x) } chk/R/internal.R0000644000176200001440000000121114436206156013161 0ustar liggesusers# necessary hack because for data frames # argument 'incomparables != FALSE' is not used (yet) .anyDuplicated <- function(x, incomparables = FALSE) { if (vld_false(incomparables) || is.null(incomparables) || !length(incomparables)) { return(anyDuplicated(x)) } if (!is.data.frame(x)) { return(anyDuplicated(x, incomparables = incomparables)) } y <- as.data.frame(lapply(x, function(col, y) col %in% y, y = incomparables)) y <- apply(y, 1, any) x <- x[!y, , drop = FALSE] anyDuplicated(x) } # remove when no longer support R < 3.6.0 str2lang <- function(text) { ex <- parse(text = text, keep.source = FALSE) ex[[1L]] } chk/R/chk-valid-name.R0000644000176200001440000000140214436206156014127 0ustar liggesusers#' Check Valid Name #' #' @description #' Checks if valid name using #' #' `identical(make.names(x[!is.na(x)]), as.character(x[!is.na(x)]))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_valid_name #' chk_valid_name("text") #' try(chk_valid_name(".1")) #' @export chk_valid_name <- function(x, x_name = NULL) { if (vld_valid_name(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be valid name%s", n = length(x)) } #' @describeIn chk_valid_name Validate Valid Name #' #' @examples #' # vld_valid_name #' vld_valid_name(".1") #' @export vld_valid_name <- function(x) identical(make.names(x[!is.na(x)]), as.character(x[!is.na(x)])) chk/R/chk-not-subset.R0000644000176200001440000000201514436206156014216 0ustar liggesusers#' Check Not Subset #' #' @description #' Checks if not all values in values using #' #' `!any(x %in% values) || !length(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_set #' #' @examples #' # chk_not_subset #' chk_not_subset(11, 1:10) #' try(chk_not_subset(1, 1:10)) #' @export chk_not_subset <- function(x, values, x_name = NULL) { if (vld_not_subset(x, values)) { return(invisible(x)) } values <- sort(unique(values), na.last = TRUE) if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk(x_name, " must not match ", cc(unique(c(x, values)), " or "), x = x, values = values) } abort_chk(x_name, " must not have any values matching ", cc(values, " or "), x = x, values = values) } #' @describeIn chk_subset Validate Not Subset #' #' @examples #' # vld_not_subset #' vld_not_subset(numeric(0), 1:10) #' vld_not_subset(1, 1:10) #' vld_not_subset(11, 1:10) #' @export vld_not_subset <- function(x, values) !any(x %in% values) || !length(x) chk/R/chk-array.R0000644000176200001440000000116414436206156013235 0ustar liggesusers#' Check Array #' #' @description #' Checks if is an array using #' #' `is.array(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_array #' chk_array(array(1)) #' try(chk_array(matrix(1))) #' @export chk_array <- function(x, x_name = NULL) { if (vld_array(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be an array", x = x) } #' @describeIn chk_array Validate Array #' #' @examples #' #' # vld_array #' vld_array(1) #' vld_array(array(1)) #' @export vld_array <- function(x) is.array(x) chk/R/chk-integer.R0000644000176200001440000000135514436206156013556 0ustar liggesusers#' Check Integer #' #' @description #' Checks if integer using #' #' `is.integer(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_integer #' chk_integer(1L) #' try(chk_integer(1)) #' @export chk_integer <- function(x, x_name = NULL) { if (vld_integer(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be integer", x = x) } #' @describeIn chk_integer Validate Integer #' #' @examples #' # vld_integer #' vld_integer(1L) #' vld_integer(matrix(1:4, nrow = 2L)) #' vld_integer(integer(0)) #' vld_integer(NA_integer_) #' vld_integer(1) #' vld_integer(TRUE) #' @export vld_integer <- function(x) is.integer(x) chk/R/chk-date.R0000644000176200001440000000135714436206156013040 0ustar liggesusers#' Check Date #' #' @description #' Checks non-missing Date scalar using #' #' `inherits(x, "Date") && length(x) == 1L && !anyNA(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_date #' chk_date(Sys.Date()) #' try(chk_date(1)) #' @export chk_date <- function(x, x_name = NULL) { if (vld_date(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a date (non-missing Date scalar)", x = x) } #' @describeIn chk_date Validate Date #' #' @examples #' # vld_date #' vld_date(Sys.Date()) #' vld_date(Sys.time()) #' vld_date(1) #' @export vld_date <- function(x) inherits(x, "Date") && length(x) == 1L && !anyNA(x) chk/R/chk-all.R0000644000176200001440000000205414436206156012666 0ustar liggesusers#' Check All #' #' @description #' Checks all elements using #' #' `all(vapply(x, chk_fun, TRUE, ...))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_alls #' #' @examples #' # chk_all #' chk_all(TRUE, chk_lgl) #' # FIXME try(chk_all(1, chk_lgl)) #' chk_all(c(TRUE, NA), chk_lgl) #' @export chk_all <- function(x, chk_fun, ..., x_name = NULL) { if (is.null(x)) { if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) return(chk_fun(x, ..., x_name = x_name)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) x_name <- paste0("all elements of ", x_name) args <- list(...) args$X <- x args$FUN <- chk_fun args$x_name <- x_name do.call("lapply", args) invisible(x) } #' @describeIn chk_all Validate All #' #' @examples #' # vld_all #' vld_all(c(TRUE, NA), vld_lgl) #' @export vld_all <- function(x, vld_fun, ...) { if (is.null(x)) { return(vld_fun(x, ...)) } args <- list(...) args$X <- x args$FUN <- vld_fun args$FUN.VALUE <- TRUE all(do.call("vapply", args)) } chk/R/chk-flag.R0000644000176200001440000000144014436206156013025 0ustar liggesusers#' 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`. #' #' @inheritParams params #' @inherit params return #' #' @family chk_logical #' #' @examples #' # chk_flag #' chk_flag(TRUE) #' try(vld_flag(1)) #' @export chk_flag <- function(x, x_name = NULL) { if (vld_flag(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a flag (TRUE or FALSE)", x = x) } #' @describeIn chk_flag Validate Flag #' #' @examples #' # vld_flag #' vld_flag(TRUE) #' vld_flag(1) #' @export vld_flag <- function(x) is.logical(x) && length(x) == 1L && !anyNA(x) chk/R/chk-character.R0000644000176200001440000000146114436206156014053 0ustar liggesusers#' Check Character #' #' @description #' Checks if character using #' #' `is.character(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_typeof #' #' @examples #' # chk_character #' chk_character("1") #' try(chk_character(1)) #' @export chk_character <- function(x, x_name = NULL) { if (vld_character(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be character", x = x) } #' @describeIn chk_character Validate Character #' #' @examples #' # vld_character #' vld_character("1") #' vld_character(matrix("a")) #' vld_character(character(0)) #' vld_character(NA_character_) #' vld_character(1) #' vld_character(TRUE) #' vld_character(factor("text")) #' @export vld_character <- function(x) is.character(x) chk/R/chk-s3-class.R0000644000176200001440000000161314436206156013546 0ustar liggesusers#' Check Type #' #' @description #' Checks inherits from S3 class using #' #' `!isS4(x) && inherits(x, class)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_is #' #' @examples #' # chk_s3_class #' chk_s3_class(1, "numeric") #' try(chk_s3_class(getClass("MethodDefinition"), "classRepresentation")) #' @export chk_s3_class <- function(x, class, x_name = NULL) { if (vld_s3_class(x, class)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) .class <- class abort_chk(x_name, " must inherit from S3 class '", .class, "'", x = x, .class = .class) } #' @describeIn chk_s3_class Validate Inherits from S3 Class #' #' @examples #' # vld_s3_class #' vld_s3_class(numeric(0), "numeric") #' vld_s3_class(getClass("MethodDefinition"), "classRepresentation") #' @export vld_s3_class <- function(x, class) !isS4(x) && inherits(x, class) chk/R/err.R0000644000176200001440000000673614507602140012146 0ustar liggesusers#' Construct Tidyverse Style Message #' #' If `tidy = TRUE` constructs a tidyverse style message by #' #' \itemize{ #' \item Capitalizing the first character if possible. #' \item Adding a trailing . if missing. #' } #' #' Also if `n != NULL` replaces the recognized `sprintf`-like types. #' #' @section `sprintf`-like types: #' #' The following recognized `sprintf`-like types can be used in a message: #' #' \describe{ #' \item{`n`}{The value of n.} #' \item{`s`}{'' if n == 1 otherwise 's'} #' \item{`r`}{'is' if n == 1 otherwise 'are'} #' \item{`y`}{'y' if n == 1 otherwise 'ie'} #' } #' #' @param ... Multiple objects that are converted to a string using #' `paste0(..., collapse = '')`. #' @param n The value of n for converting `sprintf`-like types. #' @param tidy A flag specifying whether capitalize the first character and add a missing period. #' #' @return A string of the message. #' @export #' #' @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) message_chk <- function(..., n = NULL, tidy = TRUE) { string <- p0(..., collapse = "") if (!is.null(n)) { string <- gsub("%r", if (n == 1) "is" else "are", string, fixed = TRUE) string <- gsub("%s", if (n == 1) "" else "s", string, fixed = TRUE) string <- gsub("%y", if (n == 1) "y" else "ie", string, fixed = TRUE) string <- gsub("%n", n, string, fixed = TRUE) } if (vld_true(tidy)) { if (!grepl("([.]|[?]|[!])$", string)) string <- p0(string, ".") string <- p0(toupper(substr(string, 1, 1)), substr(string, 2, nchar(string))) } string } #' Stop, Warning and Message Messages #' #' The functions call [message_chk()] to process #' the message and then #' [rlang::abort()], [rlang::warn()] and #' [rlang::inform()], respectively. #' #' The user can set the subclass. #' @param .subclass A string of the class of the error message. #' @inheritParams base::stop #' @inheritParams rlang::abort #' @inheritParams message_chk #' @name err NULL #' @describeIn err Error #' #' @export #' #' @examples #' #' # err #' try(err("there %r %n problem value%s", n = 2)) err <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL, call = rlang::caller_call(3)) { if (!is.null(.subclass)) { deprecate_soft("0.8.1", "err(.subclass)", "err(class)") class <- .subclass } args <- list2(...) named <- (names2(args) != "") msg <- exec(p0, !!!args[!named], collapse = "") msg <- message_chk(msg, n = n, tidy = tidy) if (!is.null(args$y)) { msg <- paste0( msg, "\nUse `rlang::last_error()$y` to show the object compared to." ) } rlang::abort( msg, class = class, !!!args[named], call = call ) } #' @describeIn err Warning #' #' @export #' #' @examples #' #' # wrn #' wrn("there %r %n problem value%s", n = 2) wrn <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL) { if (!is.null(.subclass)) { deprecate_soft("0.8.1", "wrn(.subclass)", "wrn(class)") class <- .subclass } warn(message_chk(..., n = n, tidy = tidy), class = class) } #' @describeIn err Message #' #' @export #' #' @examples #' #' # msg #' msg("there %r %n problem value%s", n = 2) msg <- function(..., n = NULL, tidy = TRUE, .subclass = NULL, class = NULL) { if (!is.null(.subclass)) { deprecate_soft("0.8.1", "msg(.subclass)", "msg(class)") class <- .subclass } inform(message_chk(..., n = n, tidy = tidy), class = class) } chk/R/chk-range.R0000644000176200001440000000323214507602134013204 0ustar liggesusers#' 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])` #' #' @inheritParams params #' @inherit params return #' #' @family chk_ranges #' #' @examples #' # chk_range #' chk_range(0) #' try(chk_range(-0.1)) #' @export chk_range <- function(x, range = c(0, 1), inclusive = TRUE, x_name = NULL) { if (vld_range(x, range, inclusive)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { if (inclusive && range[1] == range[2]) { abort_chk(x_name, " must be ", cc(range[1]), ", not ", cc(x), x = x, range = range) } abort_chk( x_name, " must be between ", cc(range, " and "), ifelse(isTRUE(inclusive), "", " exclusive"), ", not ", cc(x) ) } if (inclusive && range[1] == range[2]) { abort_chk(x_name, " must have values of ", cc(range[1]), x = x, range = range) } abort_chk(x_name, " must have values between ", cc(range, " and "), ifelse(isTRUE(inclusive), "", " exclusive"), x = x, range = range ) } #' @describeIn chk_range Validate Range #' #' @examples #' # vld_range #' vld_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)) #' @export vld_range <- function(x, range = c(0, 1), inclusive = TRUE) { if (isTRUE(inclusive)) { return(all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])) } all(x[!is.na(x)] > range[1] & x[!is.na(x)] < range[2]) } chk/R/chk-not-null.R0000644000176200001440000000120514436206156013663 0ustar liggesusers#' Check not NULL #' #' @description #' Checks if not NULL using #' #' `!is.null(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_nulls #' #' @examples #' # chk_not_null #' try(chk_not_null(NULL)) #' chk_not_null(1) #' @export chk_not_null <- function(x, x_name = NULL) { if (vld_not_null(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must not be NULL", x = x) } #' @describeIn chk_not_null Validate Not NULL #' #' @examples #' # vld_not_null #' vld_not_null(1) #' vld_not_null(NULL) #' @export vld_not_null <- function(x) !is.null(x) chk/R/chk-named.R0000644000176200001440000000134414436206156013203 0ustar liggesusers#' Check Named #' #' @description #' Checks if is named using #' #' `!is.null(names(x))` #' #' @inheritParams params #' @inherit params return #' #' @family chk_misc #' #' @examples #' # chk_named #' chk_named(c(x = 1)) #' try(chk_named(list(1))) #' @export chk_named <- function(x, x_name = NULL) { if (vld_named(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk((substitute(x))) abort_chk(x_name, " must be named", x = x) } #' @describeIn chk_named Validate Named #' #' @examples #' # vld_named #' vld_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)) #' @export vld_named <- function(x) !is.null(names(x)) chk/R/chk-gt.R0000644000176200001440000000175114436206156012533 0ustar liggesusers#' Check Greater Than #' #' @description #' Checks if all non-missing values are greater than value using #' #' `all(x[!is.na(x)] > value)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_ranges #' #' @examples #' # chk_gt #' chk_gt(0.1) #' try(chk_gt(c(0.1, -0.2))) #' @export chk_gt <- function(x, value = 0, x_name = NULL) { if (vld_gt(x, value)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) if (length(x) == 1L) { abort_chk(x_name, " must be greater than ", cc(value), ", not ", cc(x), x = x, value = value) } abort_chk(x_name, " must have values greater than ", cc(value), x = x, value = value) } #' @describeIn chk_gt Validate Greater Than #' #' @examples #' # vld_gt #' vld_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") #' @export vld_gt <- function(x, value = 0) all(x[!is.na(x)] > value) chk/R/chk-string.R0000644000176200001440000000143414436206156013425 0ustar liggesusers#' Check String #' #' @description #' Checks if string #' #' `is.character(x) && length(x) == 1L && !anyNA(x)` #' #' @inheritParams params #' @inherit params return #' #' @family chk_scalars #' #' @examples #' # chk_string #' chk_string("1") #' try(chk_string(1)) #' @export chk_string <- function(x, x_name = NULL) { if (vld_string(x)) { return(invisible(x)) } if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) abort_chk(x_name, " must be a string (non-missing character scalar)", x = x) } #' @describeIn chk_string Validate String #' #' @examples #' # vld_string #' vld_string("1") #' vld_string("") #' vld_string(1) #' vld_string(NA_character_) #' vld_string(c("1", "1")) #' @export vld_string <- function(x) { is.character(x) && length(x) == 1L && !anyNA(x) } chk/R/expect-chk-error.R0000644000176200001440000000125714436206156014541 0ustar liggesusers#' Expect Chk Error #' #' [expect_chk_error()] checks that code throws an error #' of class `"chk_error"` with a message that matches regexp. #' See below for more details. #' #' @inherit testthat::expect_error #' @param class Must be NULL. #' @export #' #' @examples #' expect_chk_error(chk_true(FALSE)) #' try(expect_chk_error(chk_false(FALSE))) expect_chk_error <- function(object, regexp = NULL, ..., info = NULL, label = NULL, class = NULL) { if (!is_installed("testthat")) { stop("`testhat` must be installed.") } if (!is.null(class)) stop("`class` must be NULL.") testthat::expect_error(object, regexp = regexp, class = "chk_error", ..., info = info, label = label) } chk/NEWS.md0000644000176200001440000001216114507606222012122 0ustar liggesusers # chk 0.9.1 - Fixes incorrect error message with `chk_null_or()` when `vld = chk::vld_xx`. # chk 0.9.0 - Added `chk_compatible_lengths()` and `vld_compatible_lengths()` to check that lengths of objects are 'strictly recyclable'. - Added `inclusive = TRUE` argument to `chk_range()`. - Added `upper` argument to `chk_length()`. - `vld_sorted()` and `chk_sorted()` now ignore missing values. - Soft deprecated `.subclass` for `class` argument in `err()`, `wrn()` and `msg()`. # chk 0.8.1 - Fixed bug where`check_key()` failing on sf objects. # chk 0.8.0 - Updated deprecated argument `.subclass` to `class` in rlang function calls - Added `chk_valid_name()`. - Fixed `chk_join()` with `sf` data frames. # chk 0.7.0 ## Added - Added `chkor_vld()` as faster replacement for soft-deprecated `chkor()`. - Sped up `chk_null_or()` by soft-deprecating `chk` argument for `vld` argument. - Un-deprecated `chk_count()` and `chk_length()` because so useful. - Updated error messages to precede objects which are described by their class by 'the y object of class'. ## Fixed - `chk_null_or()` now returns (invisible) x. ## Deprecated - Soft deprecated `chkor()` for `chkor_vld()` as slow. - Soft deprecated `chk` argument of `chk_null_or()` for `vld` argument. - Soft deprecated `chk_chr()`, `chk_dbl()` and `chk_wnum()` and `vld_` equivalents. - Warn deprecated `chk_count()`, `chk_dirs()`, `chk_files()`, `chk_has()`, `chk_in()`, `chk_length()`, `chk_no_missing()`, `vld_no_missing()`, `chk_proportion()` - Stop deprecated `chk_off()`, `chk_on()`, `is_chk_on()`, # chk 0.6.0 - All `chk_xx()` functions now return invisible copy of x (if passes check). - Fixed bug in `check_key()` and `check_data()` when key is undefined for `sf `objects. - `chk_whole_numeric()` now accepts `Inf` values. - Removed `LazyData: true` for DESCRIPTION file to avoid CRAN check note. # chk 0.5.0 - Added `chk_null_or()`. - Added `chk_wnum()` to check whole numeric scalars. - Added `chk_dbl()` to check double scalars. - Added `chk_chr()` to check character scalars. - Added `chk_not_subset()` to check not a subset. - Added `chk_factor()` to check factor vector. - Added `chk_character_or_factor()` factor or character vector. - Added `check_files()` and `check_dirs()` to check if all files or directories exist (or not). - Added `chk_setordered()` to check order of elements in set. - `check_values()` now checks factor levels. - Undeprecated `chk_is()` as useful for R6 objects. - Soft-deprecated `chk_datetime()` for `chk_date_time()`. # chk 0.4.0 - Added following checks - `check_names()`. - `check_dim()`. - `check_values()`. - `check_key()`. - `check_data()`. - Added following typeof chks - `chk_logical()` and `vld_logical()`. - `chk_double()` and `vld_double()`. - `chk_integer()` and `vld_integer()`. - `chk_character()` and `vld_character()`. - Added miscellaneous chks - `chk_data()` and `vld_data()`. - `chk_join()`. - Fixed - `chk_vector()` and `vld_vector()` so ignores attributes. # chk 0.3.1 - Added `expect_chk_error()`. - Added `chk_matrix()` and `vld_matrix()`. - Added `chk_array()` and `vld_array()`. - `abort_chk` now allows original arguments to be attached. - Added `chk_tz()` and `vld_tz()`. - Added `chk_matrix()` and `vld_matrix()`. - Added `chk_array()` and `vld_array()`. - Added `expect_chk_error()`. # chk 0.3.0 - Added `chk_sorted()` and `vld_sorted()`. # chk 0.2.1 ## Minor Changes - Removed `chk-benchmarking.Rmd` vignette that was causing problems for many CRAN checks. # chk 0.2.0 ## Major Changes - Added `x_name = NULL` argument to relevant `chk_` functions. - Replaced `err = FALSE` variant with `vld_` variant. - Switched from `stop()`, `warning()` and `message()` to rlang variants `abort()`, `warn()` and `inform()`. - All error messages now start with x_name. - Err capitalizes first character and adds missing period (tidyverse style). ## New Functions - `chk_all()` - `chk_atomic()` - `chk_environment()` - `chk_ext()` - `chk_has()` - `chk_not_empty()` - `chk_s3_class()` - `chk_s4_class()` - `chk_setequal()` ## Newly Exported Functions - `backtick_chk()` - `unbacktick_chk()`. ## New Arguments - `formals` argument to `chk_function()`. - `tidy = TRUE` argument to errors, warnings and messages. - `n = NULL` and `call. = FALSE` args to error message generating functions. - `ellipsis = 10L` argument to `cc()`. - `sep = ", "` arg to `cc()`. - `incomparables = FALSE` argument to `chk_unique()`. - `%y` to sprintf-like types. ## (Soft) Deprecated Functions - `chk_no_missing()` for `chk_not_any_na()`. - `chk_files()` and `chk_dirs()` for `chk_all(x, chk_file)` etc. - `deparse_backtick()` for `deparse_backtick_chk()`. - `chk_length()`, `chk_proportion()` and `chk_count()`. - `chk_on()`, `chk_off()` and `is_chk_on()`. ## Minor Changes - Changed `chk_match()` so ignores missing values. - Changed `chk_true()` (and `chk_false()`) to same behavior as `isTRUE` in R >= 3.5. - Extended `chk_unique()` to handle `incomparables != FALSE` with data frames. - Changed to `range = c(0,1)` for `chk_range()`. # chk 0.0.1 - Initial release. chk/MD50000644000176200001440000003535414507671602011351 0ustar liggesuserse826593a29cf05b5d3a05550d67c478c *DESCRIPTION c185888f9867c0d05aad5bce2b89b1ac *LICENSE 18a4fa2a08ea0e7bb0e608a996835ebd *NAMESPACE 414623178cd17d144bab096725369bca *NEWS.md 2f60ab26870a6ffbab25701efc7612cf *R/aaa.R aaf379c56bfec2e8dd260b1a630bbb5c *R/cc.R 5d2b835b4691a17220ce35b4376bdff2 *R/check-data.R e9c9b3a20c9d5d6937fc8d9f02b26723 *R/check-dim.R 97994bf0fc864c4a99cde05965e7379d *R/check-dirs.R f2b8d638d6fbda916c8507e098bf3ca6 *R/check-files.R 6b1db87e32336b7be6a1738a792930cf *R/check-key.R 25a2438a2bce93f3e7fd7134442485bc *R/check-names.R 86e782f45b344cfc059e1cf7fb9832f8 *R/check-values.R 4187c8fca56512d5cf3050935c896124 *R/chk-all-equal.R 4c2fcd42e60989764c777b70daf29d31 *R/chk-all-equivalent.R 72a30113ec458342a9041ce514d30988 *R/chk-all-identical.R 063274cf299c4d4ffca40f3c4685e4d8 *R/chk-all.R 8610c78a30981b820d5331ca738de54f *R/chk-array.R 3463efc6e84c5f5757aeab892a0b042e *R/chk-atomic.R 06d51a51760d9d957825da5c443f3c26 *R/chk-character-or-factor.R f0c73f877d04e320c566ca8fe6af092b *R/chk-character.R 0bc4f75d9f6b6018c14f0d2cc37876b2 *R/chk-chr.R a3a3f75e07d4b24b3b457e18b47d398a *R/chk-compatible-lengths.R a0401ef2cb9e19b4faaad63624417b91 *R/chk-count.R 549c1f19006fac6380f4f7a8da317503 *R/chk-data.R 029e01c79181f03b1083ed3ca22bd259 *R/chk-date.R a85141a1119049fe991492b202ddc99c *R/chk-datetime.R 89a8e5251530f605f0b0e34a70d95ec8 *R/chk-dbl.R a6405860f2cd1910b7b8996965ad475a *R/chk-dir.R ec79f9d38877b47205d4cfd054a38cfc *R/chk-double.R 41d7a9ea61a3b3d503d4611715e9eac5 *R/chk-environment.R 5024bc7e90e1f8fe558e4561ea73a308 *R/chk-equal.R 005dfb1f3e4fbf0d848fa4b4d581b216 *R/chk-equivalent.R 3a50b5e9d47c2e74b1a13bfb5cd296b3 *R/chk-ext.R b24dd90ccb8e8ab5f0d4304dbfe11062 *R/chk-factor.R 41fe240cee1b4f77ca0026018a025c6f *R/chk-false.R 4746daa3acc33f11f24914e80409aa4a *R/chk-file.R 3f984952ac7e7a14b51b3167eb7c69e0 *R/chk-flag.R fca21444a047b54bc713074af099d345 *R/chk-function.R 0da5b47a2615abd0a1b467be6d133bba *R/chk-gt.R a37a80b5f3b8ff5558ece742307ccb58 *R/chk-gte.R 54841b688411d43dc296905d69b08d09 *R/chk-identical.R 6f99b7cb551f3758c901b7411105dbd7 *R/chk-integer.R c41f78ed16367f9a7f73a25a7b065c96 *R/chk-is.R 9a5375f78181e50f34ab6367bb6d7e71 *R/chk-join.R 5f1b1a660a0770729c671d45aa91f59e *R/chk-length.R 7ba3bbb6bb966d44fda54c55aa15c2f7 *R/chk-lgl.R 6e8b74355214e18f948cb133489d2df2 *R/chk-list.R ea4d0133c4f095d3b9cfb2a95beab8ab *R/chk-logical.R b0fde53f17a24762f2ec0d3b32eb412d *R/chk-lt.R fe2f8c49d65f1f711628c5942aaaad9a *R/chk-lte.R c6fe4a166118921f25785d0b067c39b9 *R/chk-match.R 2ae4f245a2e10c2a908aeac4779fa5a8 *R/chk-matrix.R 41938c1dd9c00d79274ef086a5aaf19c *R/chk-missing.R 9e26162dd2998b9a73c3cc75a3d1b21a *R/chk-named.R 8cfbba86225ecb7f7d89cccdc535409a *R/chk-not-any-na.R d43953cc968f31b810adee611c60dd99 *R/chk-not-empty.R a0610a1ce786dfbe2d2b6b0e2f75190e *R/chk-not-missing.R ea6bcc47642b46a54f7c28e56e1fb32b *R/chk-not-null.R c1efdb458e1418d0ac907408485299da *R/chk-not-subset.R bba8fee4122901bd92ddeda719a1e777 *R/chk-null-or.R 6ba1bdbf5608196a85206c9e23bdf6de *R/chk-null.R 8a372536946f3b737b9b0f8a5203de41 *R/chk-number.R 1813e7390031d423af4e73298a212470 *R/chk-numeric.R 18da476a2a4c36fdb0771f5a9af51ab7 *R/chk-orderset.R e0ef681901465d24f47f9139cb2c086a *R/chk-package.R 46c39ebb8dca115f8bf8bd980be2990c *R/chk-range.R c37b91ed0f7506b4da84de39b5afb3ac *R/chk-s3-class.R 0034bae5d0ef1006defca631f5686205 *R/chk-s4-class.R 82618859c849a119a14642fe487cf4e9 *R/chk-scalar.R 2fba3c457e198c358bfb20840d91faa8 *R/chk-setequal.R 80df67fbaf5bfd18aa5d131eb55a3474 *R/chk-sorted.R adde872727c4225d01d8c1ab7966bcb6 *R/chk-string.R e8c7ae3d7a52726c47e0c2f9af13fa42 *R/chk-subset.R 6ecd93e626c526a272f37952aaf97509 *R/chk-superset.R 15da85fe0628ee58ebbdad4fc3419c32 *R/chk-true.R 2db2725b584d64ddd2cb7609991f38fc *R/chk-tz.R 77bb5ba23963dd3ba8e4b47bd5605ff8 *R/chk-unique.R f3ccb237aef844897a1913c5db7e9837 *R/chk-unused.R 9dad4116ae949474a47af01547fecd40 *R/chk-used.R 9312933fa2a390ec620dc75ba4097d29 *R/chk-valid-name.R 7af578de7a2e11ed19f967401b904302 *R/chk-vector.R 132797793af5ce9985eb402abec50174 *R/chk-whole-number.R a47dadf62877b95bfb6599ccad1fd73a *R/chk-whole-numeric.R 2237661129db033bd95d598f1fdc46bd *R/chk-wnum.R 2b661c584b0b66c9b36acfa5ae8166d1 *R/chkor-vld.R 12feeb7a8c74d05d919f87b7f14d166c *R/chkor.R 43f215a8f950d8d18caf9fffc3c48654 *R/deprecated.R 5cd9d80acc496cc7656a23acef38e2e3 *R/err.R 622cef554a0294e49ff731e9e374b8c8 *R/expect-chk-error.R 54ac5ce556c3b51dc0d206414e9770f7 *R/internal.R cb97326c21f3182826b58abbff3c9675 *R/namespace.R d4955d8ee62a67701119837f50ddfd80 *R/new-duplicated.R b79a003118d8484187973979086c6846 *R/p.R 5cec88c92e009f19dada9989af200067 *R/template.R 3b62dad45fd8eaaa16449551011b0347 *R/utils.R 2e6efd9969397d0ba2e51f2414ed1d17 *README.md dbe6824cf8b412c3432411d49ad3d78d *build/vignette.rds f4c590d34f55bbeb03116646639b3a11 *inst/WORDLIST 5e270ae6034b339c2a13d20a5f7d2dec *inst/doc/chk-families.R b5c296b4bde2c91be91618efeedd4b7f *inst/doc/chk-families.Rmd 902ae85ae8f2a87a2228198545b806b6 *inst/doc/chk-families.html 93c763ae3c7e9e6d06cc5862d59332b1 *inst/doc/chk.R e46bca215f6d22a4864fa99c671db4a7 *inst/doc/chk.Rmd 2e790943256a3e2a14cd518d1d465a66 *inst/doc/chk.html 4077d064b840cf5dd3d258388889dd98 *man/aaa.Rd cb807f1dfeba45a3bd724b1b746d380a *man/abort_chk.Rd daf6e076be681eb661f3fc39ade56770 *man/cc.Rd b240c4784ac08e1c940832d3d8e05d77 *man/check_data.Rd e5ef5e794ef7a2dceae019910d66404f *man/check_dim.Rd 48a2c4f222f2d24ab8f9eace5a94ae07 *man/check_dirs.Rd 5aea9d4a53e22e3583cb851a94d3670d *man/check_files.Rd ba962472b6270d60bc459794f50654b7 *man/check_key.Rd d801aa93d986745badb4f5a25973e470 *man/check_names.Rd af1ed70e6aec4f780d2baeeeb11dea9a *man/check_values.Rd 3758bf2f81ac698b61a6e3b64544bade *man/chk-package.Rd bc8fbd7540e6832a8d0241a9c3f4be1b *man/chk_all.Rd e45a860ce101ee1f273988589c50aaa7 *man/chk_all_equal.Rd 74236c69370b0e46eb1144177dc05f78 *man/chk_all_equivalent.Rd d4b3897bee413f0b23b028890ad3a36c *man/chk_all_identical.Rd d460e7e38e3cef7bb7ed88ee04457d55 *man/chk_array.Rd 1b68631dcff3b49014a06cf69bdc3eff *man/chk_atomic.Rd 5271681c6c92bc09d23bd6e84f620ae2 *man/chk_character.Rd 47436c74849474c4288cc582791ec77f *man/chk_character_or_factor.Rd c15e039cc5b43162ed082c89a946726d *man/chk_chr.Rd aa1b4a51d94f5aea8357cb8f33c92e45 *man/chk_compatible_lengths.Rd 2cc66982c82a19d2f363ec5368a1168c *man/chk_count.Rd 00773020982785732ec4d4b7bdc8eb81 *man/chk_data.Rd d2e2477d906ff09c5aa25f7cd110313f *man/chk_date.Rd 087cc235f1aab060aff82d26451d35f8 *man/chk_date_time.Rd 3585badc9b448df85a63d3550d26b543 *man/chk_dbl.Rd 1e2bc952c9809599f2cadf6f1dcfe3f5 *man/chk_deprecated.Rd 2e9f90511bdde7932f815e396ed9accd *man/chk_dir.Rd 723de2217ab57e0e2dc8ad6da31d9f13 *man/chk_double.Rd 7d2bf9966cf3651c832d76c465a2a5ad *man/chk_environment.Rd fdbd8790045e20b65ebdbc9117d13a8e *man/chk_equal.Rd 64262e036ba3b0da0b08cfa642713ef1 *man/chk_equivalent.Rd 599b3a600fffa43a6cd26f77c0e3b800 *man/chk_ext.Rd dd5cf129e650918380e7e35522840c6b *man/chk_factor.Rd 84738128b202ee9cf8f91d23e54dc44c *man/chk_false.Rd 62d65a167c9c6f25ae4f4283fc4ca508 *man/chk_file.Rd b45f21e59a15c232fc0d8a6f638f42d4 *man/chk_flag.Rd cdc6768b3b7a3188b02a4e5ba53b92d2 *man/chk_function.Rd ff2eb720baf809d875ae0b6551124eb7 *man/chk_gt.Rd 71bf04d02c89439703f70097a2743f94 *man/chk_gte.Rd 5d4df433bed098c12e91fd55e28fa061 *man/chk_identical.Rd 908dbb32fa8b2220b2b86394bee97268 *man/chk_integer.Rd 7036ac47cdf6b2d363dce385a26fc7dc *man/chk_is.Rd a8d0a5e441151a77c1a30a17dc66f59e *man/chk_join.Rd 0fd93cb8d5185b01c51be189083266fa *man/chk_length.Rd 58a193d3e1f9615e9c1926d1564f4388 *man/chk_lgl.Rd 546e73f48c0919df6a0a555cc8ed1a88 *man/chk_list.Rd b228e3ad7827919c3ae95e661dcd2194 *man/chk_logical.Rd 19b275d9f925739fb408da565dada7cb *man/chk_lt.Rd 42315137e10fa1c2fb0f104e121106a0 *man/chk_lte.Rd 55b0b5a7780724d98edf7d96635a6128 *man/chk_match.Rd 0e0e2e272b8aaa44fba7ae881d91808d *man/chk_matrix.Rd b21e967673a6524cc21fc77e260630cc *man/chk_missing.Rd d95c9b05157ebd45859a661cb2c51d0d *man/chk_named.Rd 3d8a0a4b2af62bb3bb092b27d366aae8 *man/chk_not_any_na.Rd 5930264e75970def1de8f1afc80357ea *man/chk_not_empty.Rd bfe477be7cb0c6f4ee051ea70158d757 *man/chk_not_missing.Rd b5fdd085e1c392d86be6ddc903a9963d *man/chk_not_null.Rd bcb15e0481ea8856ecebf096ba5dd19d *man/chk_not_subset.Rd 31a60325a1af6ed1e2be28e27a330933 *man/chk_null.Rd 0ba059f91b3165f2ad368082f0f1ff82 *man/chk_null_or.Rd b57f537ba8db6374a87ea08fd532e435 *man/chk_number.Rd 606db000e0dba2b62e1a37609e171d52 *man/chk_numeric.Rd 40c3e7b850300ae5e181cb217ec6ccbd *man/chk_orderset.Rd e2c07fe9b4f942804afba3ed5ee8e505 *man/chk_range.Rd 1e5da7324e0d36a7070790a5a52954b0 *man/chk_s3_class.Rd 9160ed15d2c2199d34616a9f7aa08a4c *man/chk_s4_class.Rd e47757752de0c6c9a915e4356d51fa81 *man/chk_scalar.Rd c122fdf105e908ac5e1c8f9060cddcb9 *man/chk_setequal.Rd f96744e2effad903c300f18206487395 *man/chk_sorted.Rd c985a47dd98406a052450fa0efaa16d5 *man/chk_string.Rd 58e8ba7a02be768d3c540716dbceaf87 *man/chk_subset.Rd 0a3ebf77573ab7111cee7646b791f4eb *man/chk_superset.Rd 5fdae59ad10134e6e7e5d075a8bf28cd *man/chk_true.Rd 8f5e2ecf65d0bcb3974ca898cf428dfa *man/chk_tz.Rd 9f65e78bc0dd610b6a160eb2284061e1 *man/chk_unique.Rd 62c267a717f74e389f8ab7de08c36aeb *man/chk_unused.Rd 989ffe54a2524fd79f541908b3db60f4 *man/chk_used.Rd 68e9969e69e339698d288b8351dd669a *man/chk_valid_name.Rd dbdd41458d3657d2f7bb073fc7d25f75 *man/chk_vector.Rd f48bfed1ac09434683c53d73970c3dd7 *man/chk_whole_number.Rd e8af8dae603349f1643b10a01d02c537 *man/chk_whole_numeric.Rd 199845f2a9973e0237ccab86cdfe1cc0 *man/chk_wnum.Rd 387f8af6733f8acc43e216243cd793c8 *man/chkor.Rd 917eb8344acb62c12b45bac8771c8e0a *man/chkor_vld.Rd 47c6624c05f887cdb6ea34fc66a630a6 *man/deparse_backtick_chk.Rd 15483e80c71c29a10bbf1098c1cf1561 *man/err.Rd 6cbbb6d3f257be4d3af85432c0a0dddd *man/expect_chk_error.Rd cb1e46f469cfbbbde29c8b5113e1d789 *man/figures/lifecycle-archived.svg c0d2e5a54f1fa4ff02bf9533079dd1f7 *man/figures/lifecycle-defunct.svg a1b8c987c676c16af790f563f96cbb1f *man/figures/lifecycle-deprecated.svg c3978703d8f40f2679795335715e98f4 *man/figures/lifecycle-experimental.svg 952b59dc07b171b97d5d982924244f61 *man/figures/lifecycle-maturing.svg 27b879bf3677ea76e3991d56ab324081 *man/figures/lifecycle-questioning.svg 46de21252239c5a23d400eae83ec6b2d *man/figures/lifecycle-retired.svg 6902bbfaf963fbc4ed98b86bda80caa2 *man/figures/lifecycle-soft-deprecated.svg 53b3f893324260b737b3c46ed2a0e643 *man/figures/lifecycle-stable.svg f3228000acce2b335e491936761be066 *man/figures/logo.png 234ffa92864020b0e354b6ca6ada68cf *man/message_chk.Rd c2d2ae0576d7ae2a79f88fc3b60dad09 *man/p.Rd d98d9bd86ce98393e21b30df47877214 *man/params.Rd 7fc5f2d1685e6061a8ad8dd0bf920617 *tests/testthat.R faa70dcfb76b2b66fe4974365efc01a2 *tests/testthat/test-aaa-deprecated.R d06c605bfceac9d7595d9de9c286aab4 *tests/testthat/test-cc.R a97a984b829f9c0ac2ac37d566ced4ed *tests/testthat/test-check-data.R ab7d62e383db690c752aba28beae8b42 *tests/testthat/test-check-dim.R af9c7fc2787b92f0648bb408ace3352f *tests/testthat/test-check-dirs.R 96b7366c0de010c6bb59dfdb79e20233 *tests/testthat/test-check-files.R 5c9c9337b686616fc74c2d621a1ba10a *tests/testthat/test-check-key.R c486beea4ac704bb916e194db36cbe16 *tests/testthat/test-check-names.R 465973144ed198f58d80d0346ecdccad *tests/testthat/test-check-values.R 93e7eb7a9797be141fdbedd735fa7cc6 *tests/testthat/test-chk-all.R ba277d3e7859b919891d9b53e6b572e0 *tests/testthat/test-chk-array.R 4262fd4eba9fae9ad41823181e40567f *tests/testthat/test-chk-atomic.R ac829640bfd8634cfacfbc5c6be8fd16 *tests/testthat/test-chk-character-or-factor.R cbbdf655b6440c13ef42abb8262f98bc *tests/testthat/test-chk-character.R 029cfdd0b2d014cbcc1385b1e48235cf *tests/testthat/test-chk-chr.R a35901619c71e717551955f101dbe64c *tests/testthat/test-chk-compatible-lengths.R 5d93f8ce7cdd3773e7c3f9a54f702747 *tests/testthat/test-chk-count.R c8ef3c253f70fd202a0651a62c6eb342 *tests/testthat/test-chk-data.R a15c2dc19d96a278d67fef992c9377aa *tests/testthat/test-chk-date-time.R f33fdb6cee1dbc1bff93aee79518b149 *tests/testthat/test-chk-date.R 0a400c4c42c3ae22d8dd476d2c79c79b *tests/testthat/test-chk-dbl.R fdbced5985f6f8e21badee23e12c364a *tests/testthat/test-chk-double.R 12420a406f92e9299f2bd5c2b1b15563 *tests/testthat/test-chk-environment.R d0c6e9f7ee73a6e38b6c9a3055d9a35b *tests/testthat/test-chk-factor.R 24a34c32e2e6811711ca878141c274f3 *tests/testthat/test-chk-file.R 6520e33b870d2833206177a0679fdfc8 *tests/testthat/test-chk-identical.R 439f7ce62adae02d5d1d5b2674c73f20 *tests/testthat/test-chk-integer.R 4eed3d7b30df6b7411e573d8cfbb388b *tests/testthat/test-chk-is.R ec29639891ee30fe008e561edec8c9a8 *tests/testthat/test-chk-join.R 03d284804ba3f046e962eb883d298782 *tests/testthat/test-chk-length.R cffe683ff70160a7c7d8714ecd4df045 *tests/testthat/test-chk-logical.R 2589a7e018123f6d3e06006b2a316299 *tests/testthat/test-chk-matrix.R d5cef7f74c9e12760e692abd9452f126 *tests/testthat/test-chk-missing.R e221f7fc64362d6dfe37170f685e3964 *tests/testthat/test-chk-not-any-na.R 6a406482c2a4169a76a14b9433f7ae08 *tests/testthat/test-chk-not-empty.R a9d6f8c89616158499c1942e22aad2ba *tests/testthat/test-chk-not-missing.R 3aaec2924a239bf5ce3cc216b2e09b1c *tests/testthat/test-chk-not-subset.R 1a2e4dfefc616d91ac18a560cf44f100 *tests/testthat/test-chk-null-or.R 355b1a8f2c4ef197f76216c3afe9e367 *tests/testthat/test-chk-null.R 1f77dc602af78ea057b320e5b17d0d4e *tests/testthat/test-chk-number.R 6ff252b473d6f417910e2366cad6083b *tests/testthat/test-chk-numeric.R 479e051ac792eac885fb08e6e9e86961 *tests/testthat/test-chk-orderset.R 3b8785becd2fb7ae9bc1eff7e812453e *tests/testthat/test-chk-range.R cb36179ee86207d6b22208256045275b *tests/testthat/test-chk-setequal.R a07e120c0e6ee5e504ccf33a2dd6cdd6 *tests/testthat/test-chk-sorted.R 82ee871d72f58e3ca95b3da3ef69afc5 *tests/testthat/test-chk-string.R 0ab8e0eb11a9a87583cac877b2328e34 *tests/testthat/test-chk-subset.R 68654aaedd474be8b9a6b8c7aff00ab8 *tests/testthat/test-chk-superset.R 2275512882543c69664e0a1608e28910 *tests/testthat/test-chk-true.R e2f5201847f49aef138bf04846937ae3 *tests/testthat/test-chk-type.R f7b809a0967702ae4778c92d327d499d *tests/testthat/test-chk-tz.R 0dfcddce1cdfa2f91dcc91659e1291d9 *tests/testthat/test-chk-unique.R 989bfe9b913a4a8d4f42689d15705d8e *tests/testthat/test-chk-unused.R 44100ffdf20b04c7c0ff5041d29fee51 *tests/testthat/test-chk-valid-name.R 07700895a1a156eccf0aeb1d754e0381 *tests/testthat/test-chk-vector.R 548271a38b86200b706acdef0bb557a6 *tests/testthat/test-chk-whole-number.R 91b5d9becf07e44280ddeb8d17680f90 *tests/testthat/test-chk-wnum.R 4fae5a25c15d64131939cb45663dac8e *tests/testthat/test-chkor-vld.R 95be74be917c1e6921f981830e3c423d *tests/testthat/test-chkor.R 83f337a58216a9ac8076a812bb694705 *tests/testthat/test-err.R d8bec539742826d8075c1932425f2ea8 *tests/testthat/test-expect-chk-error.R af2e6bf7d567d6bb0f1239cca2ea33a6 *tests/testthat/test-internal.R 24dbf5cd15c22f55560ffac92f4f045d *tests/testthat/test-p.R b53dfe4e9fca6c0e98998216300b22f5 *tests/testthat/test-utils.R b5c296b4bde2c91be91618efeedd4b7f *vignettes/chk-families.Rmd e46bca215f6d22a4864fa99c671db4a7 *vignettes/chk.Rmd chk/inst/0000755000176200001440000000000014507626246012010 5ustar liggesuserschk/inst/doc/0000755000176200001440000000000014507626246012555 5ustar liggesuserschk/inst/doc/chk-families.R0000644000176200001440000000021714507626246015234 0ustar liggesusers## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) chk/inst/doc/chk.html0000644000176200001440000004276414507626246014225 0ustar liggesusers Get Started with chk

Get Started with chk

Introduction

chk is an R package for developers to check user-supplied function arguments. It is designed to be simple, customizable and fast.

chk_ Functions

chk_ functions check the properties of individual objects. For example chk_flag(x) checks whether x is a flag, i.e., a non-missing logical vector of length 1.

chk_ functions are called for their side-effects, i.e., they throw an informative error if the object fails the check. Although do return an invisible copy of the first argument so they can be used in pipes.

library(chk)
y <- TRUE
chk_flag(y)
y <- NA
chk_flag(y)
#> Error:
#> ! `y` must be a flag (TRUE or FALSE).

The error messages, which follow the tidyverse style guide, are designed to allow the user to quickly identify the problem with the argument value(s) they are providing. The errors are rlang errors of subclass 'chk_error'.

vld_ Functions

Each chk_ function has a matching vld_ function which returns a flag indicating whether the object passed the check.

vld_flag(TRUE)
#> [1] TRUE
vld_flag(NA)
#> [1] FALSE

The vld_ functions allow developers to provide their own error messages.

if (!vld_flag(NA)) abort_chk("`NA` is not TRUE or FALSE!!")
#> Error:
#> ! `NA` is not TRUE or FALSE!!

Using chk

The chk_ functions are designed to be used within functions. Consequently, when constructing an error message they use the name of the object that they received as this is expected to be the name of the argument.

fun1 <- function(x) {
  chk_whole_number(x)
  # use x
}

fun1(1)
y <- 1.3
fun1(x = y)
#> Error in `fun1()`:
#> ! `x` must be a whole number (non-missing integer scalar or double equivalent).

If this is not the case, developers can provide a different name using the x_name argument.

x <- NA
chk_flag(x, x_name = "`zzz`")
#> Error:
#> ! `zzz` must be a flag (TRUE or FALSE).

IMPORTANT NOTE

As the chk_ (and vld_) functions are not expected to be directly exposed to users they don’t check any of their arguments (other than the object of interest of course!) to ensure that they are as fast as possible.

Extending chk

The chk_flag() function illustrates the general structure of a chk_ function.

chk_flag
#> function(x, x_name = NULL){
#>   if(vld_flag(x)) return(invisible(x))
#>   if(is.null(x_name))  x_name <- deparse_backtick_chk(substitute(x))
#>   abort_chk(x_name, " must be a flag (TRUE or FALSE)")
#> }
#> <bytecode: 0x7fe802835670>
#> <environment: namespace:chk>

A chk_ function initially checks the object (using its vld_ partner) and if the object passes the check immediately returns an invisible copy of the object. If, and only if, the object fails the check does the chk_ function construct and then throw an informative error message.

The deparse_backtick_chk() and abort_chk() functions are exported to make it easy for programmers to develop their own chk_ functions. The chk-lgl.R script illustrates the general template to use when developing your own chk_ functions.

abort_chk()

The abort_chk() function converts multiple arguments to a string using paste0(..., collapse = '') and provides number sensitive sprintf-like types. By default it also capitalizes the first character and adds a missing period.

abort_chk("There %r %n problem director%y%s.", n = 1)
#> Error:
#> ! There is 1 problem directory.
abort_chk("there %r %n ", "problem director%y%s", n = 2)
#> Error:
#> ! There are 2 problem directories.

check_ Functions

The check_ functions are more complex then the chk_ functions which make them slower but makes doing some general tests easier.

chk/inst/doc/chk.Rmd0000644000176200001440000000743314436206156013770 0ustar liggesusers--- title: "Get Started with chk" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Get Started with chk} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ## Introduction `chk` is an R package for developers to check user-supplied function arguments. It is designed to be simple, customizable and fast. ### `chk_` Functions `chk_` functions check the properties of individual objects. For example `chk_flag(x)` checks whether `x` is a flag, i.e., a non-missing logical vector of length 1. `chk_` functions are called for their side-effects, i.e., they throw an informative error if the object fails the check. Although do return an invisible copy of the first argument so they can be used in pipes. ```{r, error=TRUE} library(chk) y <- TRUE chk_flag(y) y <- NA chk_flag(y) ``` The error messages, which follow the [tidyverse style guide](https://style.tidyverse.org/error-messages.html), are designed to allow the user to quickly identify the problem with the argument value(s) they are providing. The errors are [rlang errors](https://rlang.r-lib.org/reference/abort.html) of subclass `'chk_error'`. ### `vld_` Functions Each `chk_` function has a matching `vld_` function which returns a flag indicating whether the object passed the check. ```{r, error=TRUE} vld_flag(TRUE) vld_flag(NA) ``` The `vld_` functions allow developers to provide their own error messages. ```{r, error=TRUE} if (!vld_flag(NA)) abort_chk("`NA` is not TRUE or FALSE!!") ``` ## Using chk The `chk_` functions are designed to be used within functions. Consequently, when constructing an error message they use the name of the object that they received as this is expected to be the name of the argument. ```{r, error = TRUE} fun1 <- function(x) { chk_whole_number(x) # use x } fun1(1) y <- 1.3 fun1(x = y) ``` If this is not the case, developers can provide a different name using the `x_name` argument. ```{r, error = TRUE} x <- NA chk_flag(x, x_name = "`zzz`") ``` **IMPORTANT NOTE** As the `chk_` (and `vld_`) functions are not expected to be directly exposed to users they don't check any of their arguments (other than the object of interest of course!) to ensure that they are as fast as possible. ## Extending chk The `chk_flag()` function illustrates the general structure of a `chk_` function. ``` r chk_flag #> function(x, x_name = NULL){ #> if(vld_flag(x)) return(invisible(x)) #> if(is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x)) #> abort_chk(x_name, " must be a flag (TRUE or FALSE)") #> } #> #> ``` A `chk_` function initially checks the object (using its `vld_` partner) and if the object passes the check immediately returns an invisible copy of the object. If, and only if, the object fails the check does the `chk_` function construct and then throw an informative error message. The `deparse_backtick_chk()` and `abort_chk()` functions are exported to make it easy for programmers to develop their own `chk_` functions. The [chk-lgl.R](https://github.com/poissonconsulting/chk/blob/master/R/chk-lgl.R) script illustrates the general template to use when developing your own `chk_` functions. ### `abort_chk()` The `abort_chk()` function converts multiple arguments to a string using `paste0(..., collapse = '')` and provides number sensitive `sprintf`-like types. By default it also capitalizes the first character and adds a missing period. ```{r, error=TRUE} abort_chk("There %r %n problem director%y%s.", n = 1) abort_chk("there %r %n ", "problem director%y%s", n = 2) ``` ### `check_` Functions The `check_` functions are more complex then the `chk_` functions which make them slower but makes doing some general tests easier. chk/inst/doc/chk.R0000644000176200001440000000176514507626246013456 0ustar liggesusers## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----error=TRUE--------------------------------------------------------------- library(chk) y <- TRUE chk_flag(y) y <- NA chk_flag(y) ## ----error=TRUE--------------------------------------------------------------- vld_flag(TRUE) vld_flag(NA) ## ----error=TRUE--------------------------------------------------------------- if (!vld_flag(NA)) abort_chk("`NA` is not TRUE or FALSE!!") ## ----error = TRUE------------------------------------------------------------- fun1 <- function(x) { chk_whole_number(x) # use x } fun1(1) y <- 1.3 fun1(x = y) ## ----error = TRUE------------------------------------------------------------- x <- NA chk_flag(x, x_name = "`zzz`") ## ----error=TRUE--------------------------------------------------------------- abort_chk("There %r %n problem director%y%s.", n = 1) abort_chk("there %r %n ", "problem director%y%s", n = 2) chk/inst/doc/chk-families.Rmd0000644000176200001440000001130214436206156015545 0ustar liggesusers--- title: "chk Families" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{chk Families} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` The `chk_` functions (and their `vld_` equivalents) can be divided into the following families. For reasons of space, the `x_name = NULL` argument is not shown. ## Check Logical Function | Code :- | :- `chk_true(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x) && x` `chk_false(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x) && !x` `chk_flag(x)` | `is.logical(x) && length(x) == 1L && !anyNA(x)` `chk_lgl(x)` | `is.logical(x) && length(x) == 1L` ## Check Scalars Function | Code :- | :------ `chk_scalar(x)` | `length(x) == 1L` `chk_number(x)` | `is.numeric(x) && length(x) == 1L && !anyNA(x)` `chk_whole_number(x)` | `vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))` `chk_string(x)` | `is.character(x) && length(x) == 1L && !anyNA(x)` `chk_date(x)` | `inherits(x, "Date") && length(x) == 1L && !anyNA(x)` `chk_datetime(x)` | `inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)` `chk_tz(x)` | `is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames()` ## Check Ranges Function | Code :- | :--- `chk_range(x, range = c(0, 1))` | `all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])` `chk_lt(x, value = 0)` | `all(x[!is.na(x)] < value)` `chk_lte(x, value = 0)` | `all(x[!is.na(x)] <= value)` `chk_gt(x, value = 0)` | `all(x[!is.na(x)] > value)` `chk_gte(x, value = 0)` | `all(x[!is.na(x)] >= value)` ## Check Equals Function | Code :-- | :- `chk_identical(x, y)` | `identical(x, y)` `chk_equal(x, y, tolerance = sqrt(.Machine$double.eps))` | `vld_true(all.equal(x, y, tolerance))` `chk_equivalent(x, y, tolerance = sqrt(.Machine$double.eps))` | `vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))` ## Check Alls Function | Code :- | :--- `chk_all(x, chk_fun, ...)` | `all(vapply(x, chk_fun, TRUE, ...))` `chk_all_identical(x)` | `length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]]))` `chk_all_equal(x, tolerance = sqrt(.Machine$double.eps))` | `length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance))` `chk_all_equivalent(x, tolerance = sqrt(.Machine$double.eps))` | `length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance))` ## Check Set Function | Code :- | :--- `chk_setequal(x, values)` | `setequal(x, values)` `chk_subset(x, values)` | `all(x %in% values)` `chk_superset(x, values)` | `all(values %in% x)` `chk_join(x, y, by)` | `identical(nrow(x), nrow(merge(x, unique(y[if (is.null(names(by))) by else names(by)]), by = by)))` ## Check Is Function | Code :- | :--- `chk_atomic(x)` | `is.atomic(x)` `chk_function(x, formals = NULL)` | `is.function(x) && (is.null(formals) || length(formals(x)) == formals)` `chk_numeric(x)` | `is.numeric(x)` `chk_s3_class(x, class)` | `!isS4(x) && inherits(x, class)` `chk_s4_class(x, class)` | `isS4(x) && methods::is(x, class)` `chk_vector(x)` | `is.vector(x)` `chk_whole_numeric(x)` | `is.integer(x) || (is.double(x) && vld_true(all.equal(x, as.integer(x))))` `chk_array(x)` | `is.array(x)` `chk_matrix(x)` | `is.matrix(x)` `chk_data(x)` | `inherits(x, "data.frame")` ## Check Typeof Function | Code :- | :--- `chk_environment(x)` | `is.environment(x)` `chk_list(x)` | `is.list(x)` `chk_logical(x)` | `is.logical(x)` `chk_double(x)` | `is.double(x)` `chk_integer(x)` | `is.integer(x)` `chk_character(x)` | `is.character(x)` ## Check NULLs Function | Code :- | :--- `chk_null(x)` | `is.null(x)` `chk_not_null(x)` | `!is.null(x)` ## Check Ellipsis Function | Code :- | :--- `chk_used(...)` | `length(list(...)) != 0L` `chk_unused(...)` | `length(list(...)) == 0L` ## Check Files Function | Code :- | :--- `chk_file(x)` | `vld_string(x) && file.exists(x) && !dir.exists(x)` `chk_ext(x, ext)` | `vld_string(x) && vld_subset(tools::file_ext(x), ext)` `chk_dir(x)` | `vld_string(x) && dir.exists(x)` ## Check Miscellaneous Function | Code :- | :-- `chk_match(x, regexp = ".+")` | `all(grepl(regexp, x[!is.na(x)]))` `chk_named(x)` | `!is.null(names(x))` `chk_not_empty(x)` | `length(x) != 0L` `chk_not_any_na(x)` | `!anyNA(x)` `chk_unique(x, incomparables = FALSE)` | `!anyDuplicated(x, incomparables = incomparables)` `chk_sorted(x)` | `is.unsorted(x)` ## Check **Function** `check_data(x, values = NULL, exclusive = FALSE, order = FALSE, nrow = numeric(0), key = character(0))` `check_dim(x, dim = length, values = numeric(0), dim_name = NULL)` `check_key(x, key = character(0), na_distinct = FALSE)` `check_names(x, names = character(0), exclusive = FALSE, order = FALSE)` `check_values(x, values)` chk/inst/doc/chk-families.html0000644000176200001440000004131014507626246015776 0ustar liggesusers chk Families

chk Families

The chk_ functions (and their vld_ equivalents) can be divided into the following families. For reasons of space, the x_name = NULL argument is not shown.

Check Logical

Function Code
chk_true(x) is.logical(x) && length(x) == 1L && !anyNA(x) && x
chk_false(x) is.logical(x) && length(x) == 1L && !anyNA(x) && !x
chk_flag(x) is.logical(x) && length(x) == 1L && !anyNA(x)
chk_lgl(x) is.logical(x) && length(x) == 1L

Check Scalars

Function Code
chk_scalar(x) length(x) == 1L
chk_number(x) is.numeric(x) && length(x) == 1L && !anyNA(x)
chk_whole_number(x) vld_number(x) && (is.integer(x) || vld_true(all.equal(x, trunc(x))))
chk_string(x) is.character(x) && length(x) == 1L && !anyNA(x)
chk_date(x) inherits(x, "Date") && length(x) == 1L && !anyNA(x)
chk_datetime(x) inherits(x, "POSIXct") && length(x) == 1L && !anyNA(x)
chk_tz(x) is.character(x) && length(x) == 1L && !anyNA(x) && x %in% OlsonNames()

Check Ranges

Function Code
chk_range(x, range = c(0, 1)) all(x[!is.na(x)] >= range[1] & x[!is.na(x)] <= range[2])
chk_lt(x, value = 0) all(x[!is.na(x)] < value)
chk_lte(x, value = 0) all(x[!is.na(x)] <= value)
chk_gt(x, value = 0) all(x[!is.na(x)] > value)
chk_gte(x, value = 0) all(x[!is.na(x)] >= value)

Check Equals

Function Code
chk_identical(x, y) identical(x, y)
chk_equal(x, y, tolerance = sqrt(.Machine$double.eps)) vld_true(all.equal(x, y, tolerance))
chk_equivalent(x, y, tolerance = sqrt(.Machine$double.eps)) vld_true(all.equal(x, y, tolerance, check.attributes = FALSE))

Check Alls

Function Code
chk_all(x, chk_fun, ...) all(vapply(x, chk_fun, TRUE, ...))
chk_all_identical(x) length(x) < 2L || all(vapply(x, vld_identical, TRUE, y = x[[1]]))
chk_all_equal(x, tolerance = sqrt(.Machine$double.eps)) length(x) < 2L || all(vapply(x, vld_equal, TRUE, y = x[[1]], tolerance = tolerance))
chk_all_equivalent(x, tolerance = sqrt(.Machine$double.eps)) length(x) < 2L || all(vapply(x, vld_equivalent, TRUE, y = x[[1]], tolerance = tolerance))

Check Set

Function Code
chk_setequal(x, values) setequal(x, values)
chk_subset(x, values) all(x %in% values)
chk_superset(x, values) all(values %in% x)
chk_join(x, y, by) identical(nrow(x), nrow(merge(x, unique(y[if (is.null(names(by))) by else names(by)]), by = by)))

Check Is

Function Code
chk_atomic(x) is.atomic(x)
chk_function(x, formals = NULL) is.function(x) && (is.null(formals) || length(formals(x)) == formals)
chk_numeric(x) is.numeric(x)
chk_s3_class(x, class) !isS4(x) && inherits(x, class)
chk_s4_class(x, class) isS4(x) && methods::is(x, class)
chk_vector(x) is.vector(x)
chk_whole_numeric(x) is.integer(x) || (is.double(x) && vld_true(all.equal(x, as.integer(x))))
chk_array(x) is.array(x)
chk_matrix(x) is.matrix(x)
chk_data(x) inherits(x, "data.frame")

Check Typeof

Function Code
chk_environment(x) is.environment(x)
chk_list(x) is.list(x)
chk_logical(x) is.logical(x)
chk_double(x) is.double(x)
chk_integer(x) is.integer(x)
chk_character(x) is.character(x)

Check NULLs

Function Code
chk_null(x) is.null(x)
chk_not_null(x) !is.null(x)

Check Ellipsis

Function Code
chk_used(...) length(list(...)) != 0L
chk_unused(...) length(list(...)) == 0L

Check Files

Function Code
chk_file(x) vld_string(x) && file.exists(x) && !dir.exists(x)
chk_ext(x, ext) vld_string(x) && vld_subset(tools::file_ext(x), ext)
chk_dir(x) vld_string(x) && dir.exists(x)

Check Miscellaneous

Function Code
chk_match(x, regexp = ".+") all(grepl(regexp, x[!is.na(x)]))
chk_named(x) !is.null(names(x))
chk_not_empty(x) length(x) != 0L
chk_not_any_na(x) !anyNA(x)
chk_unique(x, incomparables = FALSE) !anyDuplicated(x, incomparables = incomparables)
chk_sorted(x) is.unsorted(x)

Check

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

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

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

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

check_values(x, values)

chk/inst/WORDLIST0000644000176200001440000000040714436206156013176 0ustar liggesusersAlls Amies Backtick CMD Codecov Galonski Lifecycle NULLs ORCID POSIXct Tidyverse Typeof Un Unbacktick Undeprecated alls arg args backticked backtraces brac checkr customise customizable datacheckr funder ie lgl pkgdown rlang sprintf testthat tidyverse typeof vld