We can use !!!
operator with tibble. Some examples:
library(tidyverse)
#first case
listoflists1=list(c(1,2,3,4),c(5,6,7,8)) %>%
set_names(c("col1", "col2"))
tibble(!!!listoflists1)
#> # A tibble: 4 × 2
#> col1 col2
#> <dbl> <dbl>
#> 1 1 5
#> 2 2 6
#> 3 3 7
#> 4 4 8
#second case
listoflists2=list(list(1:4),list(5:8)) %>%
set_names(c("col1", "col2"))
tibble(!!!listoflists2) %>%
unnest(names(.))
#> # A tibble: 4 × 2
#> col1 col2
#> <int> <int>
#> 1 1 5
#> 2 2 6
#> 3 3 7
#> 4 4 8
#third case
listoflists3=list(list(1,2,3,4),list(5,6,7,8)) %>% set_names(c("col1", "col2"))
tibble(!!!listoflists3) %>%
unnest(names(.))
#> # A tibble: 4 × 2
#> col1 col2
#> <dbl> <dbl>
#> 1 1 5
#> 2 2 6
#> 3 3 7
#> 4 4 8
#it is possible to use unnest without cols argument but it will throw a warning message.
Created on 2021-09-22 by the reprex package (v2.0.0)