Skip to content

Commit 2ca0759

Browse files
committed
length rule and cross rules, n arg fix, coerce arg change
1 parent d5b4018 commit 2ca0759

18 files changed

Lines changed: 463 additions & 137 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
.quarto
77
docs
88
inst/doc
9+
/doc/
10+
/Meta/

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# fluffy (development version)
22

3+
## New Features
4+
5+
* New `length` rule added to the `Registry`. This rule checks that the length of a data field is exactly equal to the value specified by the `length` schema field. This removes the need to specify both a `min_length` and `max_length` with the same value when enforcing an exact length.
6+
7+
* New `length_and_min_length` and `length_and_max_length` cross rules added to the `Registry`. These rules check that the `min_length` and `max_length` rules are not specified when a `length` rule is present.
8+
9+
* The `coerce` rule now accepts functions with multiple arguments when passed directly to a `Schema` or `Validator`, allowing base `as.*()` functions to be used as `coerce` rules in schema definitions. However, only the field value is passed to the function; any additional arguments are ignored. Functions with multiple arguments still cannot be added to the `Registry@coerce_map`, as `add_coerce_rule()` enforces a strict one-argument function signature.
10+
11+
## Bug fixes
12+
13+
* Fixed the `allowed_type_mismatch` and `forbidden_type_mismatch` cross rules so that they use the `Registry@type_map` to obtain the function used for type checking when `type` is a string, and use the supplied function directly when `type` is a function. Previously, function-valued `type` fields caused an error, while character-valued `type` fields could result in incorrect type checking because the class of the `allowed`/`forbidden` field was compared directly with the `type` field. This could produce false positives, such as an integer `allowed`/`forbidden` field being flagged as a type mismatch when `type` was "numeric".
14+
15+
* Fixed incorrect argument-count checking for the `type`, `predicate`, and `apply` rules.
16+
317
# fluffy 1.0.0
418

519
* Initial CRAN submission.

R/aaa_Schema.r

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
#' [adding custom rules](../doc/custom-rules.html).
7575
#' @seealso [add_rule] for adding rules to a `Registry`. [Validator] for
7676
#' validating data against a `Schema`.
77+
#' @note
78+
#' The `coerce` rule may use functions with multiple arguments when
79+
#' passed directly to a `Schema` or `Validator`. Only the field value is
80+
#' passed to the function, and any additional arguments are ignored. Thus,
81+
#' `as.numeric` is valid as a `coerce` rule in a schema definition, but cannot
82+
#' be added to a `Registry`, which enforces a strict one-argument function
83+
#' signature.
7784
#' @examples
7885
#' # A valid schema
7986
#' s <- Schema(list(

R/abb_add_rule_generics.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
#' (the full schema/data in the respective walks) are named arguments
7272
#' and must be named as such.
7373
#'
74+
#' The `coerce` rule may use functions with multiple arguments when
75+
#' passed directly to a `Schema` or `Validator` (additional arguments are
76+
#' ignored), but `Registry` addition is stricter and enforces a single
77+
#' argument function signature.
78+
#'
7479
#' Despite [Registry] using environments to store rules, which are
7580
#' mutable, [add_rule] methods copy the existing environment
7681
#' and the new rule into a new environment, meaning that the

0 commit comments

Comments
 (0)