Skip to content

feat: multiple_of constraint for stabilize_int() and stabilize_dbl() #283

Description

@jonthegeek

Summary

As a package developer, in order to require that numbers be multiples of a given step (JSON Schema multipleOf), I would like to reject values that are not evenly divisible by a base value.

Details

JSON Schema multipleOf requires that a numeric instance be divisible by a positive number with no remainder (e.g. multipleOf: 2 for even integers, multipleOf: 0.01 for currency). stbl has no such constraint.

Proposed signature

stabilize_int(x, ..., multiple_of = NULL)
stabilize_dbl(x, ..., multiple_of = NULL)

Arguments

  • multiple_of (numeric(1), positive) — Each value must be an integer multiple of this. NULL (default) skips the check.

Returns the coerced numeric vector, unchanged when all elements are multiples.

Behavior

  • Element-wise divisibility check; report offending element locations (element failure, per Include locations object in conditions for element-wise failures #274).
  • For dbl, use a tolerance to avoid floating-point false negatives (document the approach).
  • Add to the int and dbl stabilizers, their _scalar() variants, and specify_int() / specify_dbl().

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSON schemanecessary for JSON schema supportai-created 🤖📝written by AI; requires vetting by a human; remove this label after reviewingdblint

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions