Type: | Package |
Title: | Casting Values into Shape |
Version: | 0.2.0 |
Description: | Helper functions with a consistent interface to coerce and verify the types and shapes of values for input checking. |
License: | Apache License (≥ 2.0) |
Encoding: | UTF-8 |
LazyData: | true |
Depends: | R (≥ 3.1.2) |
Imports: | rlang (≥ 0.3.1), magrittr |
RoxygenNote: | 6.1.0 |
Suggests: | testthat, covr |
NeedsCompilation: | no |
Packaged: | 2019-02-26 15:41:55 UTC; kevinykuo |
Author: | Kevin Kuo |
Maintainer: | Kevin Kuo <kevin.kuo@rstudio.com> |
Repository: | CRAN |
Date/Publication: | 2019-02-26 16:00:03 UTC |
Pipe operator
Description
See %>%
for more details.
Usage
lhs %>% rhs
Cast values into shape
Description
These functions verify and attempt to coerce values into the specified types and shapes. If they are unsuccessful in the coercion, an error is thrown.
Usage
cast_integer(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_scalar_integer(x, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_integer(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_nullable_scalar_integer(x, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_integer_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_integer_list(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_double(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_scalar_double(x, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_double(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_nullable_scalar_double(x, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_double_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_double_list(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_character(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_scalar_character(x, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_character(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_nullable_scalar_character(x, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_character_list(x, n = NULL, allow_na = FALSE,
allow_null = FALSE, id = NULL, return_id = FALSE)
cast_nullable_character_list(x, n = NULL, allow_na = FALSE,
id = NULL, return_id = FALSE)
cast_string(x, allow_na = FALSE, allow_null = FALSE, id = NULL,
return_id = FALSE)
cast_nullable_string(x, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_string_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_string_list(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_logical(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_scalar_logical(x, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_logical(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_nullable_scalar_logical(x, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_logical_list(x, n = NULL, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
cast_nullable_logical_list(x, n = NULL, allow_na = FALSE, id = NULL,
return_id = FALSE)
cast_choice(x, choices, allow_na = FALSE, allow_null = FALSE,
id = NULL, return_id = FALSE)
Arguments
x |
A vector. |
n |
The required length of the vector. If |
allow_na |
Whether to allow |
allow_null |
Whether to allow |
id |
Name given to the input to aid the user in identifying the bad value. |
return_id |
Whether to return the ID as an attribute. This should only be set to |
choices |
A character, numeric, or integer vector of allowed values. |
Examples
# Cast a double vector to integer
cast_integer(c(1, 2))
# Cast a numeric to a string
cast_string(4.5)
# Cast an integer vector to a list of doubles
cast_double_list(1:4)
Ensure Conditions on a Value
Description
Checks that the input value satisfies specified conditions
Usage
certify(x, ..., allow_null = FALSE, id = NULL, return_id = FALSE)
gt(l)
gte(l)
lt(u)
lte(u)
bounded(l = NULL, u = NULL, incl_lower = TRUE, incl_upper = TRUE)
Arguments
x |
The value to be checked. |
... |
Conditions to be checked; should be functions that return TRUE/FALSE. |
allow_null |
Whether to allow null input. |
id |
Name given to the input to aid the user in identifying the bad value. |
return_id |
Whether to return the ID as an attribute. This should only be set to |
l |
Lower bound for the inequality condition. |
u |
Upper bound for the inequality condition. |
incl_lower |
Whether to include the left endpoint. |
incl_upper |
Whether to include the right endpoint. |