Skip to content

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

Description

@mir-cat

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviormap 🗺️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions