Skip to content

hoist doesn't handle duplicate names well #834

@mgirlich

Description

@mgirlich

hoist() simply overwrites existing columns and doesn't check that the names of the ... argument are unique:

library(tidyr)
df <- tibble(
  character = c("Toothless", "Dory"),
  metadata = list(
    list(
      species = "dragon",
      color = "black",
      films = c(
        "How to Train Your Dragon",
        "How to Train Your Dragon 2",
        "How to Train Your Dragon: The Hidden World"
       )
    ),
    list(
      species = "blue tang",
      color = "blue",
      films = c("Finding Nemo", "Finding Dory")
    )
  )
)

# doesn't care about duplicate name
hoist(.data = df,
  .col = metadata,
  film = list("films", 1L),
  film = list("films", 3L)
)
#> # A tibble: 2 x 4
#>   character film                 film                             metadata      
#>   <chr>     <chr>                <chr>                            <list>        
#> 1 Toothless How to Train Your D… How to Train Your Dragon: The H… <named list […
#> 2 Dory      Finding Nemo         <NA>                             <named list […

# overwrite existing column
hoist(.data = df,
  .col = metadata,
  character = list("films", 2L)
)
#> # A tibble: 2 x 2
#>   metadata         character                 
#>   <list>           <chr>                     
#> 1 <named list [3]> How to Train Your Dragon 2
#> 2 <named list [3]> Finding Dory

Created on 2019-12-13 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions