{knapplyr}
Utility functions to facilitate robust R programming that are
heavily-inspired by {purrr}
.
{knapplyr}
is meant to serve as a controlled environment for
development and testing. The functions are not so much intended to be
imported elsewhere, but instead to make it easy to have sane, tested,
dependency-free utilities that can be easily used as internal, utility
functions in other packages.
This is mainly for personal purposes, but if you’d like to use it, just
add the /R/knapply-utils.R
file to your package’s /R
folder. The
functions will then be accessible just like any of your package’s other
functions.
.map*()
-ersl1 <- list(a = 1:3, b = -1:-3)
l1
#> $a
#> [1] 1 2 3
#>
#> $b
#> [1] -1 -2 -3
.map(l1, as.character)
#> $a
#> [1] "1" "2" "3"
#>
#> $b
#> [1] "-1" "-2" "-3"
.map_chr(l1, paste, collapse = ", ")
#> a b
#> "1, 2, 3" "-1, -2, -3"
.map_int(l1, sum)
#> a b
#> 6 -6
.map_dbl(l1, function(x) sum(x) * 2.5)
#> a b
#> 15 -15
.map_lgl(l1, function(x) all(x > 0))
#> a b
#> TRUE FALSE
.map2*()
-ersl2 <- list(a = 4:6, b = -4:-6)
l2
#> $a
#> [1] 4 5 6
#>
#> $b
#> [1] -4 -5 -6
.map2(l1, l2, c)
#> $a
#> [1] 1 2 3 4 5 6
#>
#> $b
#> [1] -1 -2 -3 -4 -5 -6
.map2_chr(l1, l2, paste, collapse = " | ")
#> a b
#> "1 4 | 2 5 | 3 6" "-1 -4 | -2 -5 | -3 -6"
.map2_int(l1, l2, min)
#> a b
#> 1 -6
.map2_dbl(l1, l2, function(x, y) sort(c(x, y))[[1L]])
#> a b
#> 1 -6
.map2_lgl(l1, l2, function(x, y) all(c(x, y) > 0))
#> a b
#> TRUE FALSE
n <- .set_names("named")
n
#> named
#> "named"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.