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

hoist(): not possible to create a list_of column #998

Closed
mgirlich opened this issue Jul 16, 2020 · 0 comments · Fixed by #1200
Closed

hoist(): not possible to create a list_of column #998

mgirlich opened this issue Jul 16, 2020 · 0 comments · Fixed by #1200
Labels
bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames

Comments

@mgirlich
Copy link
Contributor

It seems that it is currently not possible to create a list_of column.

library(tidyr)
df <- tibble(
  character = c("Toothless", "Dory"),
  metadata = list(
    list(colors = "black"),
    list(colors = "blue")
  )
)

# Goal: colors should be a `list_of<chr>`
df %>% 
  hoist(metadata,
    "colors",
    .ptype = list(colors = vctrs::list_of(.ptype = character()))
  )
#> Error: Can't convert <character> to <list_of<character>>.

# --> add explicit transformation function via `.transform`
df %>% 
  hoist(metadata,
    "colors",
    .ptype = list(colors = vctrs::list_of(.ptype = character())),
    .transform = list(
      colors = ~ {
        vctrs::list_of(!!!.x, .ptype = character())
      })
  )
#> Error: Can't simplfy 'colors'; contains a nested list

# --> simplify = FALSE doesn't combine to list_of
df %>% 
  hoist(metadata,
    "colors",
    .transform = list(
      colors = ~ {
        vctrs::list_of(!!!.x, .ptype = character())
      }),
    .simplify = FALSE
  )
#> # A tibble: 2 x 2
#>   character colors         
#>   <chr>     <list>         
#> 1 Toothless <list<chr> [1]>
#> 2 Dory      <list<chr> [1]>

Created on 2020-07-16 by the reprex package (v0.3.0)

@hadley hadley added bug an unexpected problem or unintended behavior rectangling 🗄️ converting deeply nested lists into tidy data frames labels Aug 28, 2020
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 rectangling 🗄️ converting deeply nested lists into tidy data frames
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants