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

Create named lists when using map_* on stringifyable argument #691

Closed
holgerbrandl opened this issue Jul 11, 2019 · 2 comments
Closed

Create named lists when using map_* on stringifyable argument #691

holgerbrandl opened this issue Jul 11, 2019 · 2 comments

Comments

@holgerbrandl
Copy link

As discussed in https://stackoverflow.com/a/56949741/590437 it would be great if map_* could produce a named list (either by default or via method parameter), if the argument is coercible to a string.

Example implementation (overwriting map in the current environment)

map = function(x, ...){
    if (is.integer(x) | is.character(x)) { # this should be done in a more clever way
        purrr::map(x, ...) %>% set_names(x)
    }else {
        purrr::map(x, ...) 
    }
}

1 : 5 %>% map(~ .x + 1)
@gabrielodom
Copy link

Any traction on this?

@lionel-
Copy link
Member

lionel- commented Oct 11, 2019

This is by design. Adding the names might be useful for data analysis but would make purrr harder to program with because of failed assumptions. As a package, purrr is at the intersection of data analysis and package programming, which explains this kind of design decisions.

Also the SO issue is missing the recommended solution to this problem:

letters %>% set_names() %>% map(toupper)

@lionel- lionel- closed this as completed Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants