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

modify_depth(x, 2, fun) is not equivalent to x[] <- map(x, ~ map(., fun)) when deepest level is a vector #359

Closed
mir-cat opened this issue Aug 3, 2017 · 1 comment
Labels
bug an unexpected problem or unintended behavior map 🗺️

Comments

@mir-cat
Copy link

mir-cat commented Aug 3, 2017

Example:


list_of_vectors <- list(one = c(1, 2, 3), two = c(4, 5, 6))

purrr::map(list_of_vectors, ~purrr::map(., ~.+1))
#> $one
#> $one[[1]]
#> [1] 2
#> 
#> $one[[2]]
#> [1] 3
#> 
#> $one[[3]]
#> [1] 4
#> 
#> 
#> $two
#> $two[[1]]
#> [1] 5
#> 
#> $two[[2]]
#> [1] 6
#> 
#> $two[[3]]
#> [1] 7

purrr::modify_depth(list_of_vectors, 2, ~.+1)
#> Error: List not deep enough

I think at_depth used to not give this error in this same context. I feel that modify_depth is working exactly as intended, but it is still confusing that it should be so easy to construct a case that explicitly contradicts the documentation for the modify_depth documentation. Maybe map shouldn't work on vectors as well?

@hadley

This comment has been minimized.

@hadley hadley added the reprex needs a minimal reproducible example label Feb 5, 2018
@mir-cat mir-cat changed the title modify_depth(x, 2, fun) is not equivalent to x[] <- map(x, ~ map(., fun)) when there is a vector in the list modify_depth(x, 2, fun) is not equivalent to x[] <- map(x, ~ map(., fun)) when deepest level is a vector Feb 5, 2018
@hadley hadley added bug an unexpected problem or unintended behavior map 🗺️ and removed reprex needs a minimal reproducible example labels May 5, 2018
lionel- added a commit to lionel-/lowliner that referenced this issue Dec 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior map 🗺️
Projects
None yet
Development

No branches or pull requests

2 participants