Skip to content

bind_rows() shifts named list identifiers when multiple consecutive NULL elements are present #4296

@koncina

Description

@koncina

When row-binding a named list containing multiple consecutive NULL elements the resulting data frame identifiers (using the .id argument) are shifted:

library(tidyverse)

list(a = tibble(expected_id = "a"),
     b = NULL,
     c = NULL,
     d = tibble(expected_id = "d"),
     c = NULL,
     e = tibble(expected_id = "e")) %>% 
  bind_rows(.id = "id")
#> # A tibble: 3 x 2
#>   id    expected_id
#>   <chr> <chr>      
#> 1 a     a          
#> 2 c     d          
#> 3 d     e

Created on 2019-03-20 by the reprex package (v0.2.1)

Single NULL elements are handled accurately:

library(tidyverse)

list(a = tibble(expected_id = "a"),
     b = NULL,
     c = tibble(expected_id = "c"),
     d = NULL,
     e = tibble(expected_id = "e")) %>% 
  bind_rows(.id = "id")
#> # A tibble: 3 x 2
#>   id    expected_id
#>   <chr> <chr>      
#> 1 a     a          
#> 2 c     c          
#> 3 e     e

Created on 2019-03-20 by the reprex package (v0.2.1)

Metadata

Metadata

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions