purrr icon indicating copy to clipboard operation
purrr copied to clipboard

Unable to `zap` list elements using `list_modify`

Open TylerGrantSmith opened this issue 3 years ago • 1 comments

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

TylerGrantSmith avatar May 04 '21 14:05 TylerGrantSmith

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.

juliasilge avatar Jul 21 '21 23:07 juliasilge

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)

hadley avatar Aug 25 '22 09:08 hadley

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

mccarthy-m-g avatar Oct 08 '22 05:10 mccarthy-m-g

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 avatar Mar 02 '23 21:03 groditi

@groditi update to 1.0.0.

hadley avatar Mar 02 '23 23:03 hadley