recycling_help: Recycling and recyclability

View source: R/recyclableN.R

recycling_helpR Documentation

Recycling and recyclability

Description

Check for and conduct recycling in the environment that calls functions from this family.

Arguments are recyclable if all of their lengths are divisors of the argument with the greatest length subject to any settings in the optional arguments .n, .min, .max, and/or .targ.

Usage

recycling_help()

recyclable_ns(..., .n = NULL, .min = NULL, .max = NULL, .targ = NULL)

recyclable(..., .n = NULL, .min = 1, .max = NULL, .targ = NULL, .err = FALSE)

recycle(..., .n = NULL, .min = 1, .max = NULL, .targ = NULL)

Arguments

...

For recycle, named arguments to be recycled in the environment of the calling function. For recyclable_n, one or more objects containing only positive whole number values (atomized before processing).

.n

Either NULL or a complete positive whole-number vec (?cmp_psw_vec) giving the set of valid recycled argument lengths.

.min

Either NULL or a complete positive whole-number scalar (?cmp_psw_scl) giving the minimum valid recycled argument length.

.max

Either NULL or a complete positive whole-number scalar giving the maximum valid recycled argument length.

.targ

Either NULL or a complete positive whole-number scalar giving the target length of recycled arguments. May be greater than length(av(...)).

.err

TRUE or FALSE indicating whether to throw an error if the ... arguments are not recyclable.

Value

A logical scalar

  ⁠recyclableN, recyclable⁠

The NULL object

  recycle

Functions

  • recyclable_ns(): Checks whether numeric scalar arguments in ... indicate recyclable lengths, subject to restrictions in .n, .min, .max, and .targ.

  • recyclable(): Checks whether arguments in ... are recyclable, subject to restrictions in .n, .min, .max, and .targ.

  • recycle(): Recycles named arguments in ... in the environment of the calling function, subject to restrictions in .n, .min, .max, and .targ.

See Also

Other environments: callers(), os(), value_exists()

Other meta: callers(), console_help(), dot_args(), pause(), ply_help(), purge_help(), run()

Examples

egN1. <- 1
egN2 <- 1:2
egN3 <- 1:3
egN4 <- 1:4
egC1 <- paste0("'", letters[egN1], "'")
egC2 <- paste0("'", letters[egN2], "'")
egC3 <- paste0("'", letters[egN3], "'")
egC4 <- paste0("'", letters[egN4], "'")

egRecycle <- function(A, B, C) {
  asc <- function(n, v) {paste0(n, " = c(", paste0(v, collapse = ", "), ")")}
  recycle(A = A, B = B, C = C)
  cat(paste0(asc("A", A), "\n", asc("B", B), "\n", asc("C", C)))
}

egRecycle(egN4, egC2, egN1)
egRecycle(egC1, egN2, egC4)
egRecycle(egN3, egC3, egC1)
egRecycle(egN3, egC3, egN3)
recyclableN(1:3)
recyclableN(2, 4, 8)
recyclableN(2, 4, 8, .n = c(2, 4, 8, 16))
recyclableN(2, 4, 8, .min = 4)
recyclableN(2, 4, 8, .max = 4)
recyclableN(2, 4, 8, .targ = 7)
recyclableN(2, 4, 8, .targ = 8)
recyclableN(2, 4, 8, .targ = 16)
recyclable(egN1, egC2, egN3)
recyclable(egN4, egC2, egN1)
recyclable(egC1, egN2, egC4)
recyclable(egN3, egC3, egC1)
recyclable(egN3, egC3, egN3)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.