Skip to content

modify_depth fails when higher levels have NULLs #655

Description

@gregleleu

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviormodify 🛠️

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions