Skip to content

Use tidyselect in map_at #608

@ColinFay

Description

@ColinFay

It would be nice if map_at() could incorporate tidyselect functions:

library(purrr)
library(tidyselect)

map_at_two <- function(.x, .at, .f, ...){
  outvars <- vars_select(.vars = names(.x), .at)
  map_at(.x, outvars, .f, ...)
}

x <- list(a = "b", b = "c", aa = "bb")

map_at_two(x, contains("a"), toupper)
#> $a
#> [1] "B"
#> 
#> $b
#> [1] "c"
#> 
#> $aa
#> [1] "BB"

map_at_two(x, 1, toupper)
#> $a
#> [1] "B"
#> 
#> $b
#> [1] "c"
#> 
#> $aa
#> [1] "bb"

map_at_two(x, "a", toupper)
#> $a
#> [1] "B"
#> 
#> $b
#> [1] "c"
#> 
#> $aa
#> [1] "bb"

x <- list("b", "c", "bb")

map_at_two(x, contains("a"), toupper)
#> Error: No tidyselect variables were registered

<sup>Created on 2019-01-02 by the [reprex package](https://reprex.tidyverse.org) (v0.2.1)</sup>

{tidyselect} has purrr as a dependencies, so it might imply that {purrr} functions used in {tidyselect} have to be rewritten.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions