I've recently noticed some new-to-me behavior when printing count()-ed tibbles in html_notebook documents. In the code below, the bad
object is a coerced tibble which is then count()-ed. This object, when printed, generates rownames in the displayed table. The good
object, a count()-ed object which is coerced to a tibble as a final step does not display rownames.
Strangely, the class and attributes of both objects look identical, but they fail an identical(attrib.as.set = FALSE)
check -- an option I've not used before and am at a loss to explain.
There's a subtle difference in the display of the two tibbles even in this rendered reprex, with the bad
object showing an asterisk in the rownames column...another display quirk I'm not sure how to interpret.
I'm expecting behavior similar to the good
object, that which printed, rownames are not displayed.
Clarifications and corrections greatly appreciated!
library(dplyr, warn.conflicts = FALSE)
bad <- mtcars %>% tibble::as_tibble() %>% count(disp)
good <- mtcars %>% count(disp) %>% tibble::as_tibble()
identical(bad, good, attrib.as.set = FALSE)
#> [1] FALSE
bad
#> # A tibble: 27 x 2
#> disp n
#> * <dbl> <int>
#> 1 71.1 1
#> 2 75.7 1
#> 3 78.7 1
#> 4 79 1
#> 5 95.1 1
#> 6 108 1
#> 7 120. 1
#> 8 120. 1
#> 9 121 1
#> 10 141. 1
#> # … with 17 more rows
good
#> # A tibble: 27 x 2
#> disp n
#> <dbl> <int>
#> 1 71.1 1
#> 2 75.7 1
#> 3 78.7 1
#> 4 79 1
#> 5 95.1 1
#> 6 108 1
#> 7 120. 1
#> 8 120. 1
#> 9 121 1
#> 10 141. 1
#> # … with 17 more rows
Created on 2021-02-03 by the reprex package (v1.0.0)
Session info
sessionInfo()
#> R version 4.0.3 (2020-10-10)
#> Platform: x86_64-apple-darwin17.0 (64-bit)
#> Running under: macOS Big Sur 10.16
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices datasets utils methods base
#>
#> other attached packages:
#> [1] dplyr_1.0.4
#>
#> loaded via a namespace (and not attached):
#> [1] knitr_1.31 magrittr_2.0.1 tidyselect_1.1.0 R6_2.5.0
#> [5] rlang_0.4.10 fansi_0.4.1 stringr_1.4.0 styler_1.3.2
#> [9] highr_0.8 tools_4.0.3 xfun_0.19 utf8_1.1.4
#> [13] cli_2.3.0 DBI_1.1.0 htmltools_0.5.0 ellipsis_0.3.1
#> [17] assertthat_0.2.1 yaml_2.2.1 digest_0.6.27 tibble_3.0.6
#> [21] lifecycle_0.2.0 crayon_1.4.0 purrr_0.3.4 vctrs_0.3.6
#> [25] fs_1.5.0 glue_1.4.2 evaluate_0.14 rmarkdown_2.6
#> [29] reprex_1.0.0 stringi_1.5.3 compiler_4.0.3 pillar_1.4.7
#> [33] generics_0.1.0 backports_1.2.1 renv_0.12.5 pkgconfig_2.0.3