Skip to content

Commit

Permalink
Don’t use partial matching for attr_getter()
Browse files Browse the repository at this point in the history
Changed the `attr_getter()` fuction to no longer uses partial matching.
For example, if an `x` object has a `labels` attribute but no `label`
attribute, `attr_getter("label")(x)` will no longer extract the `labels`
attribute (fixes tidyverse#460).

Also added some documentation on the `attr_getter()` function.
  • Loading branch information
huftis committed Feb 7, 2018
1 parent b6a0304 commit 05395de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions NEWS.md
@@ -1,5 +1,10 @@
# purrr 0.2.4.9000

* `attr_getter()` no longer uses partial matching. For example,
if an `x` object has a `labels` attribute but no `label` attribute,
`attr_getter("label")(x)` will no longer extract the `labels`
attribute (#460, @huftis).

* `flatten_dfr()` and `flatten_dfc()` now aborts if dplyr is not installed. (#454)

* `imap_dfr()` now works with `.id` argument is provided (#429)
Expand Down
7 changes: 6 additions & 1 deletion R/pluck.R
Expand Up @@ -16,6 +16,11 @@
#' Furthermore, `pluck()` never partial-matches unlike `$` which will
#' select the `disp` object if you write `mtcars$di`.
#'
#' `attr_getter()` generates an attribute accessor function;
#' i.e., it generates a function for extracting an attribute with
#' a given name. Unlike the base R `attr()` function with default
#' options, it doesn't use partial matching.
#'
#' @details
#'
#' Since it handles arbitrary accessor functions, `pluck()` is a type
Expand Down Expand Up @@ -83,5 +88,5 @@ pluck <- function(.x, ..., .default = NULL) {
#' @param attr An attribute name as string.
attr_getter <- function(attr) {
force(attr)
function(x) attr(x, attr)
function(x) attr(x, attr, exact = TRUE)
}
5 changes: 5 additions & 0 deletions man/pluck.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05395de

Please sign in to comment.