Reputation: 18561
Recently I have updated to tidyr
version 1.0.0 on two different machines (PC and mac) running slightly different R and package versions.
The print output of tiydr::nest
now shows slight differences. My question seems related to this post, but is not. I am not interested in how to create identical results between the new nest
and nest_legacy
(this difference is what the post above is about). I am rather interested in why different print outputs occur, although the same tidyr
version is used, and how I can fix this (the print output of my PC doesn't look correct).
Here is the output on my mac:
library(tidyr)
nested_tbl_mac <- iris %>%
tidyr::nest(data = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width))
nested_tbl_mac
#> # A tibble: 3 x 2
#> Species data
#> <fct> <list<df[,4]>>
#> 1 setosa [50 × 4]
#> 2 versicolor [50 × 4]
#> 3 virginica [50 × 4]
nested_tbl_mac[[2]] %>% class
#> [1] "vctrs_list_of" "vctrs_vctr"
Created on 2019-11-25 by the reprex package (v0.3.0)
Here is the output from my pc:
library(tidyr)
nested_tbl_pc <- iris %>%
tidyr::nest(data = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width))
nested_tbl_pc
#> # A tibble: 3 x 2
#> Species data
#> <fct> <S3: vctrs_list_of>
#> 1 setosa 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4.8, 4~
#> 2 versicolor 7.0, 6.4, 6.9, 5.5, 6.5, 5.7, 6.3, 4.9, 6.6, 5.2, 5.0, 5.9, 6~
#> 3 virginica 6.3, 5.8, 7.1, 6.3, 6.5, 7.6, 4.9, 7.3, 6.7, 7.2, 6.5, 6.4, 6~
nested_tbl_pc[[2]] %>% class
#> [1] "vctrs_list_of" "vctrs_vctr"
Created on 2019-11-25 by the reprex package (v0.3.0)
It seems like a printing issue to me. However, unlike in this post here I haven’t tweaked my printing options on neither of my machines.
The only packages I have loaded are tidyr
and all base packages.
(.packages())
#> [1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
#> [7] "base"
Finally, here a comparison between the versions of tidyr
and all packages imported by tidyr
on both of my machines (last row shows the R version):
#> package version_pc version_mac
#> <chr> <chr> <chr>
#> 1 tidyr 1.0.0 1.0.0
#> 2 dplyr 0.8.3 0.8.3
#> 3 ellipsis 0.3.0 0.2.0.1
#> 4 glue 1.3.0 1.3.1
#> 5 magrittr 1.5 1.5
#> 6 purrr 0.3.2 0.3.3
#> 7 Rcpp 1.0.2 1.0.2
#> 8 rlang 0.4.1 0.4.0
#> 9 stringi 1.2.4 1.2.2
#> 10 tibble 2.1.1 2.1.3
#> 11 tidyselect 0.2.5 0.2.5
#> 12 utils 3.5.1 3.5.0
#> 13 vctrs 0.2.0 0.2.0
#> 14 lifecycle 0.1.0 0.1.0
#> 15 R.Version 3.5.1 3.5.0
Update: I have now updated all packages imported by tidyr
on my PC which had smaller version numbers than my mac (glue
, purrr
and tibble
) and this does not solve the problem. I would like to refrain from downgrading to lower versions on my PC for ellipsis
, rlang
, stringi
and utils
.
Solution: As Matt hinted at in his answer, the cause of the problem was rooted in the pillar
package. Updating from version 1.2.1
to 1.4.2
solved the printing issue. I approached the problem as a tidyr
issue, but it actually was an issue of how (nested) tibbles get printed. Therefore, I should have looked at the dependencies of the tibble
package as well.
Upvotes: 4
Views: 106
Reputation: 2987
I'm not 100% on this, but I think this is due to the printing options of pillar
, and according to this you can override the printing which may produce what you're looking for:
print.tbl_df <- function(x, ...) {
print.data.frame(x, ...)
invisible(x)
}
Upvotes: 1
Reputation: 1708
I'm getting the same result as the mac
-version on my PC/windows machine.
This doesn't seem like a serious issue to me.
Note that you're not using the latest version of R. This could be it.
library(tidyr)
nested_tbl_mac <- iris %>%
tidyr::nest(data = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width))
nested_tbl_mac
#> # A tibble: 3 x 2
#> Species data
#> <fct> <list<df[,4]>>
#> 1 setosa [50 x 4]
#> 2 versicolor [50 x 4]
#> 3 virginica [50 x 4]
Created on 2019-11-25 by the reprex package (v0.3.0)
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 3.6.1 (2019-07-05)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz Europe/Paris
#> date 2019-11-25
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
#> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
#> callr 3.3.2 2019-09-22 [1] CRAN (R 3.6.1)
#> cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
#> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.1)
#> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1)
#> dplyr 0.8.3 2019-07-04 [1] CRAN (R 3.6.1)
#> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0)
#> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)
#> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0)
#> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.1)
#> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0)
#> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1)
#> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1)
#> lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1)
#> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
#> memoise 1.1.0.9000 2019-07-08 [1] Github (hadley/memoise@1650ad7)
#> pillar 1.4.2 2019-06-29 [1] CRAN (R 3.6.0)
#> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1)
#> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0)
#> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
#> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.1)
#> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
#> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1)
#> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1)
#> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0)
#> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.1)
#> rmarkdown 1.17 2019-11-13 [1] CRAN (R 3.6.1)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0)
#> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
#> testthat 2.3.0 2019-11-05 [1] CRAN (R 3.6.1)
#> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0)
#> tidyr * 1.0.0 2019-09-11 [1] CRAN (R 3.6.1)
#> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.0)
#> usethis 1.5.1.9000 2019-10-24 [1] Github (r-lib/usethis@b1fca08)
#> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
#> vctrs 0.2.0 2019-07-05 [1] CRAN (R 3.6.1)
#> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
#> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1)
#> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0)
#> zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0)
#>
#> [1] C:/Users/[redacted]/Documents/R/win-library/3.6
#> [2] C:/Program Files/R/R-3.6.1/library
Upvotes: 0