Skip to content

.ragged default in modify_depth is not correcly evaluated #530

Closed

Description

@cderv
library(purrr)
x1 <- list(
  list(1),
  list(list(2))
)
# it works as expected
modify_depth(x1, .depth = -1, ~ . + 1, .ragged = TRUE) %>% str()
#> List of 2
#>  $ :List of 1
#>   ..$ : num 2
#>  $ :List of 1
#>   ..$ :List of 1
#>   .. ..$ : num 3

# .ragged should also be TRUE by default here because .depth is negative
modify_depth(x1, .depth = -1, ~ . + 1)
#> Error: List not deep enough

We have an error because value of .ragged is FALSE, because .depth is modified
internally before .ragged is evaluated.

purrr/R/modify.R

Lines 203 to 212 in 977f1fd

modify_depth.default <- function(.x, .depth, .f, ..., .ragged = .depth < 0) {
stopifnot(is_integerish(.depth, n = 1))
if (.depth < 0) {
.depth <- vec_depth(.x) + .depth
}
.f <- as_mapper(.f, ...)
modify_depth_rec(.x, .depth, .f, ..., .ragged = .ragged)
}

Activity

  1. added a commit that references this issue on Aug 12, 2018
    ef0a3c2
  2. added a commit that references this issue on Sep 22, 2018
    1aabb31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions