
favr casting and recycling helpers
Source:R/casting_recycling_helpers.r
favr_casting_recycling_helpers.RdThese functions signal to favr functions to undergo casting, lossy casting, and/or recycling. Each can only be used wihtin calls to specific favr functions and will error if used outside them. Specifically:
Value
No return value, called for side effects only. Will error if called outside of a favr calling context (see Description and Examples).
Details
These functions add attributes and/or a class to their inputs that signal transformations to occur within the favr caller.
Examples
try(cast(10)) # errors outside of favr calling context
#> Error in eval(expr, envir) : Caused by error in `cast()`.
#> `cast()` must be used within `enforce()` or `schema()` calls.
x <- 1.5
cast_if_not(x = lossy(integer()))
class(x) # integer
#> [1] "integer"
enforce(x ~ list(cast(double()), recycle(5)))
class(x) # numeric
#> [1] "numeric"
length(x) # 5
#> [1] 5
x <- 1.5
enforce(x ~ coerce(type = integer(), size = 5, lossy = TRUE))
class(x) # integer
#> [1] "integer"
length(x) # 5
#> [1] 5