A special index for nested tibble

I am used to working with nested columns whose each row looks like <tibble [1 x 1]>

However, a function produced the list column with each row of the following format:
<tibble[,1] [1 × 1]>. How should I interpret the structure of such list columns and how can I turn the latter format to a format that is similar to <tibble [1 x 1]>?

reprex:

Local .Rprofile detected at /lustre/scratch123/hgi/mdt1/teams/martin/tl11/elgh_prs/.Rprofile


library(tibble)

#> Warning: package 'tibble' was built under R version 3.6.3

library(purrr)

library(dplyr)

#> Warning: replacing previous import 'vctrs::data_frame' by 'tibble::data_frame'

#> when loading 'dplyr'

#> 

#> Attaching package: 'dplyr'

#> The following objects are masked from 'package:stats':

#> 

#>     filter, lag

#> The following objects are masked from 'package:base':

#> 

#>     intersect, setdiff, setequal, union

mutate(tibble(a=1),b = map(a, ~ tibble(c=1)))

#> # A tibble: 1 x 2

#>       a b                   

#>   <dbl> <list>              

#> 1     1 <tibble[,1] [1 × 1]>

Created on 2021-04-20 by the reprex package (v2.0.0)

Session info


sessioninfo::session_info()

#> ─ Session info ───────────────────────────────────────────────────────────────

#>  setting  value                       

#>  version  R version 3.6.1 (2019-07-05)

#>  os       Ubuntu 18.04.5 LTS          

#>  system   x86_64, linux-gnu           

#>  ui       X11                         

#>  language (EN)                        

#>  collate  en_GB.utf8                  

#>  ctype    en_GB.utf8                  

#>  tz       Europe/London               

#>  date     2021-04-20                  

#> 

#> ─ Packages ───────────────────────────────────────────────────────────────────

#>  package     * version date       lib source                            

#>  backports     1.1.4   2019-04-10 [2] CRAN (R 3.6.0)                    

#>  cli           2.4.0   2021-04-05 [1] CRAN (R 3.6.3)                    

#>  conflicted    1.0.4   2019-06-21 [1] CRAN (R 3.6.1)                    

#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 3.6.1)                    

#>  digest        0.6.27  2020-10-24 [1] CRAN (R 3.6.1)                    

#>  dplyr       * 1.0.0   2020-05-29 [1] CRAN (R 3.6.1)                    

#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 3.6.1)                    

#>  evaluate      0.14    2019-05-28 [2] CRAN (R 3.6.3)                    

#>  fansi         0.4.2   2021-01-15 [1] CRAN (R 3.6.1)                    

#>  fs            1.5.0   2020-07-31 [1] CRAN (R 3.6.1)                    

#>  generics      0.0.2   2018-11-29 [1] CRAN (R 3.6.1)                    

#>  glue          1.4.2   2020-08-27 [1] CRAN (R 3.6.1)                    

#>  highr         0.8     2019-03-20 [1] CRAN (R 3.6.1)                    

#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 3.6.1)                    

#>  knitr         1.31    2021-01-27 [1] CRAN (R 3.6.1)                    

#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 3.6.3)                    

#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 3.6.1)                    

#>  pillar        1.6.0   2021-04-13 [1] CRAN (R 3.6.3)                    

#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 3.6.1)                    

#>  ps            1.6.0   2021-02-28 [1] CRAN (R 3.6.3)                    

#>  purrr       * 0.3.4   2020-04-17 [1] CRAN (R 3.6.1)                    

#>  R6            2.5.0   2020-10-28 [1] CRAN (R 3.6.1)                    

#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 3.6.1)                    

#>  rlang         0.4.10  2020-12-30 [1] CRAN (R 3.6.1)                    

#>  rmarkdown     2.6.6   2021-02-12 [1] Github (rstudio/rmarkdown@a62cb20)

#>  rstudioapi    0.11    2020-02-07 [1] CRAN (R 3.6.1)                    

#>  sessioninfo   1.1.1   2018-11-05 [2] CRAN (R 3.6.3)                    

#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 3.6.1)                    

#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.6.1)                    

#>  styler        1.3.2   2020-02-23 [1] CRAN (R 3.6.1)                    

#>  tibble      * 3.1.0   2021-02-25 [1] CRAN (R 3.6.3)                    

#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 3.6.1)                    

#>  utf8          1.2.1   2021-03-12 [1] CRAN (R 3.6.3)                    

#>  vctrs         0.3.7   2021-03-29 [1] CRAN (R 3.6.3)                    

#>  withr         2.4.1   2021-01-26 [1] CRAN (R 3.6.1)                    

#>  xfun          0.21    2021-02-10 [1] CRAN (R 3.6.1)                    

#>  yaml          2.2.1   2020-02-01 [2] CRAN (R 3.6.3)                    

#> 

#> [1] /nfs/users/nfs_t/tl11/R/x86_64-conda_cos6-linux-gnu-library/3.6

#> [2] /lustre/scratch119/realdata/mdt2/teams/martin/users/tl11/conda_env/renv_renv/lib/R/library

map returns a list, which is the reason that the b column of the tibble is a list.

suppressPackageStartupMessages({
  library(dplyr)
  library(purrr)
})

tib <- tibble(a=1,b = map(a, ~ tibble(c=1)))

tib
#> # A tibble: 1 x 2
#>       a b                   
#>   <dbl> <list>              
#> 1     1 <tibble[,1] [1 × 1]>

str(tib)
#> tibble[,2] [1 × 2] (S3: tbl_df/tbl/data.frame)
#>  $ a: num 1
#>  $ b:List of 1
#>   ..$ : tibble[,1] [1 × 1] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ c: num 1

tib %>% mutate(c = unlist(b))
#> # A tibble: 1 x 3
#>       a b                        c
#>   <dbl> <list>               <dbl>
#> 1     1 <tibble[,1] [1 × 1]>     1

Thanks for the reply!

I think what I want is <tibble [1 x 1]> and not completely it to a double. Do you know how I can do that? (I am using an older version of tibble here)
`

library(tidyverse)
tibble(a=1)  %>% 
    mutate(b = map(a, ~ tibble(c=1)))
#> # A tibble: 1 x 2
#>       a b               
#>   <dbl> <list>          
#> 1     1 <tibble [1 x 1]>

Created on 2021-04-21 by the reprex package (v1.0.0)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United Kingdom.1252 
#>  ctype    English_United Kingdom.1252 
#>  tz       Europe/London               
#>  date     2021-04-21                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date       lib source                            
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)                    
#>  backports     1.1.10  2020-09-15 [1] CRAN (R 4.0.2)                    
#>  blob          1.2.1   2020-01-20 [1] CRAN (R 4.0.2)                    
#>  broom         0.7.1   2020-10-02 [1] CRAN (R 4.0.2)                    
#>  cellranger    1.1.0   2016-07-27 [1] CRAN (R 4.0.2)                    
#>  cli           2.3.0   2021-01-31 [1] CRAN (R 4.0.3)                    
#>  colorspace    1.4-1   2019-03-18 [1] CRAN (R 4.0.2)                    
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.3)                    
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.2)                    
#>  dbplyr        1.4.4   2020-05-27 [1] CRAN (R 4.0.2)                    
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.3)                    
#>  dplyr       * 1.0.4   2021-02-02 [1] CRAN (R 4.0.3)                    
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)                    
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)                    
#>  fansi         0.4.2   2021-01-15 [1] CRAN (R 4.0.3)                    
#>  forcats     * 0.5.0   2020-03-01 [1] CRAN (R 4.0.2)                    
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)                    
#>  generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.3)                    
#>  ggplot2     * 3.3.2   2020-06-19 [1] CRAN (R 4.0.2)                    
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)                    
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.2)                    
#>  haven         2.3.1   2020-06-01 [1] CRAN (R 4.0.2)                    
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)                    
#>  hms           1.0.0   2021-01-13 [1] CRAN (R 4.0.3)                    
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3)                    
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)                    
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.0.3)                    
#>  knitr         1.31    2021-01-27 [1] CRAN (R 4.0.3)                    
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)                    
#>  lubridate     1.7.9   2020-06-08 [1] CRAN (R 4.0.2)                    
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)                    
#>  modelr        0.1.8   2020-05-19 [1] CRAN (R 4.0.2)                    
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.2)                    
#>  pillar        1.4.7   2020-11-20 [1] CRAN (R 4.0.3)                    
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)                    
#>  purrr       * 0.3.4   2020-04-17 [1] CRAN (R 4.0.2)                    
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.3)                    
#>  Rcpp          1.0.6   2021-01-15 [1] CRAN (R 4.0.3)                    
#>  readr       * 1.4.0   2020-10-05 [1] CRAN (R 4.0.2)                    
#>  readxl        1.3.1   2019-03-13 [1] CRAN (R 4.0.2)                    
#>  reprex        1.0.0   2021-01-27 [1] CRAN (R 4.0.4)                    
#>  rlang         0.4.10  2020-12-30 [1] CRAN (R 4.0.3)                    
#>  rmarkdown     2.6.6   2021-02-12 [1] Github (rstudio/rmarkdown@a62cb20)
#>  rvest         0.3.6   2020-07-25 [1] CRAN (R 4.0.2)                    
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.2)                    
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.3)                    
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)                    
#>  stringr     * 1.4.0   2019-02-10 [1] CRAN (R 4.0.2)                    
#>  styler        1.3.2   2020-02-23 [1] CRAN (R 4.0.3)                    
#>  tibble      * 3.0.6   2021-01-29 [1] CRAN (R 4.0.3)                    
#>  tidyr       * 1.1.2   2020-08-27 [1] CRAN (R 4.0.2)                    
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)                    
#>  tidyverse   * 1.3.0   2019-11-21 [1] CRAN (R 4.0.3)                    
#>  utf8          1.1.4   2018-05-24 [1] CRAN (R 4.0.2)                    
#>  vctrs         0.3.6   2020-12-17 [1] CRAN (R 4.0.3)                    
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)                    
#>  xfun          0.20    2021-01-06 [1] CRAN (R 4.0.3)                    
#>  xml2          1.3.2   2020-04-23 [1] CRAN (R 4.0.3)                    
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)                    
#> 
#> [1] C:/Users/timing/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.3/library

The example from the documentation shows that although tibbles can contain tibbles the enclosed tibbles display as the class of the innermost layer.

suppressPackageStartupMessages({
  library(tibble)
})
# Tibbles can contain columns that are tibbles or matrices
# if the number of rows is compatible. Unnamed tibbled are
# spliced, i.e. the inner columns are inserted into the
# tibble under construction.
tib <- tibble(
  a = 1:3,
  tibble(
    b = 4:6,
    c = 7:9
  ),
  d = tibble(
    e = tibble(
      f = b
    )
  ))

tib
#> # A tibble: 3 x 4
#>       a     b     c d$e$f
#>   <int> <int> <int> <int>
#> 1     1     4     7     4
#> 2     2     5     8     5
#> 3     3     6     9     6

str(tib[4])
#> tibble[,1] [3 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ d: tibble[,1] [3 × 1] (S3: tbl_df/tbl/data.frame)
#>   ..$ e: tibble[,1] [3 × 1] (S3: tbl_df/tbl/data.frame)
#>   .. ..$ f: int [1:3] 4 5 6

The objects you are seeing in both the old and new versions of tibble are the same. The fact that they print differently is a bug introduced by the CRAN version of pillar. It has been fixed in the dev version.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.