keep_at() and discard_at() are similar to [ or dplyr::select(): they
return the same type of data structure as the input, but only containing
the requested elements. (If you're looking for a function similar to
[[ see pluck()/chuck()).
Examples
x <- c(a = 1, b = 2, cat = 10, dog = 15, elephant = 5, e = 10)
x |> keep_at(letters)
#> a b e
#> 1 2 10
x |> discard_at(letters)
#> cat dog elephant
#> 10 15 5
# Can also use a function
x |> keep_at(\(x) nchar(x) == 3)
#> cat dog
#> 10 15
x |> discard_at(\(x) nchar(x) == 3)
#> a b elephant e
#> 1 2 5 10
