purrr
purrr copied to clipboard
Unable to `zap` list elements using `list_modify`
I feel this is likely related to #822, but currently you cannot zap
list elements.
library(purrr)
x <- list(a = 2)
list_modify(x, a = zap())
#> named list()
x <- list(a = list(2))
list_modify(x, a = zap())
#> $a
#> $a[[1]]
#> [1] 2
I am looking at the documentation and examples and it seems like it was intended/planned to be able to zap
elements of lists that are themselves lists? Notice where it says:
# Remove values
str(list_modify(x, z = zap()))
but then does not remove the z
value.
Looks like this was fixed in 0.3.4:
library(purrr)
x <- list(a = 2)
list_modify(x, a = zap())
#> named list()
x <- list(a = list(2))
list_modify(x, a = zap())
#> named list()
Created on 2022-08-25 by the reprex package (v2.0.1)
This appears to still be bugged in 0.3.4. In the documentation example it still isn't removing the z
value:
# Remove values
list_modify(x, z = zap())
#> List of 3
#> $ x: int [1:10] 1 2 3 4 5 6 7 8 9 10
#> $ y: num 4
#> $ z:List of 2
#> ..$ a: num 1
#> ..$ b: num 2
Where the result should look like:
# Remove values
list_modify(x, z = zap())
#> List of 3
#> $ x: int [1:10] 1 2 3 4 5 6 7 8 9 10
#> $ y: num 4
I'm still experiencing this with 0.3.5 as well `
x <- list(x = 1:10, y = 4, z = list(a = 1, b = 2)) str(purrr::list_modify(x, z = purrr::zap())) List of 3 $ x: int [1:10] 1 2 3 4 5 6 7 8 9 10 $ y: num 4 $ z:List of 2 ..$ a: num 1 ..$ b: num 2 `
@groditi update to 1.0.0.