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 fails when higher levels have NULLs #655

Closed
gregleleu opened this issue Mar 6, 2019 · 1 comment · Fixed by #879
Closed

modify_depth fails when higher levels have NULLs #655

gregleleu opened this issue Mar 6, 2019 · 1 comment · Fixed by #879
Labels
bug an unexpected problem or unintended behavior modify 🛠️

Comments

@gregleleu
Copy link

Hi,
modify_depth fails when higher levels have a mix of NULLs and non-NULLs e.g.

> aa <- list(a = NULL, b = list(b1 = NULL, b2 = "hello"))
> aa
$a
NULL

$b
$b$b1
NULL

$b$b2
[1] "hello"


> modify_depth(aa, 
+              .depth = 2,
+              is.character,
+              .ragged = TRUE
+              )
Error in .x[[i]] : subscript out of bounds

I would expect

$a
NULL

$b
$b$b1
NULL

$b$b2
[1] "TRUE"

Works when the first level has no NULLs

> aa <- list(a = "hi", b = list(b1 = NULL, b2 = "hello"))
> aa
$a
[1] "hi"

$b
$b$b1
NULL

$b$b2
[1] "hello"


> modify_depth(aa, 
+              .depth = 2,
+              is.character,
+              .ragged = TRUE
+              )
$a
[1] "TRUE"

$b
$b$b1
[1] FALSE

$b$b2
[1] TRUE

And btw why is the upper level type-stable, and not the lower level ?

And why is it the same when .ragged = FALSE ?

> modify_depth(aa, 
+              .depth = 2,
+              is.character
+              )
$a
[1] "TRUE"

$b
$b$b1
[1] FALSE

$b$b2
[1] TRUE

Thanks!

@hadley
Copy link
Member

hadley commented Aug 25, 2022

Reperex:

library(purrr)
aa <- list(a = NULL, b = list(b1 = NULL, b2 = "hello"))
modify_depth(aa, .depth = 2, is.character, .ragged = TRUE)
#> Error in .x[[i]]: subscript out of bounds

Created on 2022-08-25 by the reprex package (v2.0.1)

hadley added a commit that referenced this issue Aug 25, 2022
Fixes #655. Fixes #746. Fixes #753. Closes #754
hadley added a commit that referenced this issue Aug 25, 2022
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 modify 🛠️
Projects
None yet
3 participants