Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tidyselect in map_at #608

Closed
ColinFay opened this issue Jan 2, 2019 · 3 comments · Fixed by #619
Closed

Use tidyselect in map_at #608

ColinFay opened this issue Jan 2, 2019 · 3 comments · Fixed by #619
Labels
tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day

Comments

@ColinFay
Copy link
Contributor

ColinFay commented Jan 2, 2019

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.

@lionel-
Copy link
Member

lionel- commented Jan 2, 2019

Sorry, purrr is unlikely to gain any NSE features. The right way to do it would be to take a vars() list by the way, as in mutate_at() etc.

@lionel- lionel- closed this as completed Jan 2, 2019
@ColinFay
Copy link
Contributor Author

@lionel- just in case, this is the issue I've referred to tonight :)

@lionel- lionel- reopened this Jan 15, 2019
@ColinFay
Copy link
Contributor Author

ColinFay commented Jan 19, 2019

Working on this one today

@batpigandme batpigandme added the tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day label Jan 19, 2019
@ColinFay ColinFay mentioned this issue Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tidy-dev-day 🤓 Tidyverse Developer Day rstd.io/tidy-dev-day
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants