Skip to content

Commit e8c4016

Browse files
Meghansahahadley
andauthored
Improve pluck/chuck/keep_at/discard_at documentation (#1219)
Fixes #1183 Co-authored-by: Hadley Wickham <h.wickham@gmail.com>
1 parent bc964e1 commit e8c4016

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

R/keep.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ compact <- function(.x, .p = identity) {
6363

6464
#' Keep/discard elements based on their name/position
6565
#'
66-
#' @inheritParams map_at
66+
#' @description
67+
#' `keep_at()` and `discard_at()` are similar to `[` or `dplyr::select()`: they
68+
#' return the same type of data structure as the input, but only containing
69+
#' the requested elements. (If you're looking for a function similar to
70+
#' `[[` see [pluck()]/[chuck()]).
71+
#'
6772
#' @seealso [keep()]/[discard()] to keep/discard elements by value.
73+
#' @inheritParams map_at
6874
#' @export
6975
#' @examples
7076
#' x <- c(a = 1, b = 2, cat = 10, dog = 15, elephant = 5, e = 10)

R/pluck.R

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
#'
33
#' @description
44
#' `pluck()` implements a generalised form of `[[` that allow you to index
5-
#' deeply and flexibly into data structures. It always succeeds, returning
5+
#' deeply and flexibly into data structures. (If you're looking for an
6+
#' equivalent of `[`, see [keep_at()].) `pluck()` always succeeds, returning
67
#' `.default` if the index you are trying to access does not exist or is `NULL`.
8+
#' (If you're looking for a variant that errors, try [chuck()].)
79
#'
810
#' `pluck<-()` is the assignment equivalent, allowing you to modify an object
911
#' deep within a nested data structure.
@@ -39,9 +41,12 @@
3941
#' * These accessors never partial-match. This is unlike `$` which
4042
#' will select the `disp` object if you write `mtcars$di`.
4143
#'
42-
#' @seealso [attr_getter()] for creating attribute getters suitable
43-
#' for use with `pluck()` and `chuck()`. [modify_in()] for
44-
#' applying a function to a pluck location.
44+
#' @seealso
45+
#' * [attr_getter()] for creating attribute getters suitable for use
46+
#' with `pluck()` and `chuck()`.
47+
#' * [modify_in()] for applying a function to a plucked location.
48+
#' * [keep_at()] is similar to `pluck()`, but retain the structure
49+
#' of the list instead of converting it into a vector.
4550
#' @export
4651
#' @examples
4752
#' # Let's create a list of data structures:

man/keep_at.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/pluck.Rd

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)