ropensci / skimr

A frictionless, pipeable approach to dealing with summary statistics
https://docs.ropensci.org/skimr
1.12k stars 79 forks source link

print() with include_summary = F returns skimmed table twice #715

Closed MichalLauer closed 2 years ago

MichalLauer commented 2 years ago

Hello,

when I was playing around with skimr, I found out that print(x, include_summary = FALSE) returns the table twice. Am I doing something wrong?

Reprex and session info:

library(skimr)
#> Warning: package 'skimr' was built under R version 4.2.1
skimmed <- skim(mtcars)
print(skimmed, include_summary = FALSE)
#> 
#> ── Variable type: numeric ──────────────────────────────────────────────────────
#>    skim_variable n_missing complete_rate    mean      sd    p0    p25    p50
#>  1 mpg                   0             1  20.1     6.03  10.4   15.4   19.2 
#>  2 cyl                   0             1   6.19    1.79   4      4      6   
#>  3 disp                  0             1 231.    124.    71.1  121.   196.  
#>  4 hp                    0             1 147.     68.6   52     96.5  123   
#>  5 drat                  0             1   3.60    0.535  2.76   3.08   3.70
#>  6 wt                    0             1   3.22    0.978  1.51   2.58   3.32
#>  7 qsec                  0             1  17.8     1.79  14.5   16.9   17.7 
#>  8 vs                    0             1   0.438   0.504  0      0      0   
#>  9 am                    0             1   0.406   0.499  0      0      0   
#> 10 gear                  0             1   3.69    0.738  3      3      4   
#> 11 carb                  0             1   2.81    1.62   1      2      2   
#>       p75   p100 hist 
#>  1  22.8   33.9  ▃▇▅▁▂
#>  2   8      8    ▆▁▃▁▇
#>  3 326    472    ▇▃▃▃▂
#>  4 180    335    ▇▇▆▃▁
#>  5   3.92   4.93 ▇▃▇▅▁
#>  6   3.61   5.42 ▃▃▇▁▂
#>  7  18.9   22.9  ▃▇▇▂▁
#>  8   1      1    ▇▁▁▁▆
#>  9   1      1    ▇▁▁▁▆
#> 10   4      5    ▇▁▆▁▂
#> 11   4      8    ▇▂▅▁▁
#> $numeric
#> 
#> ── Variable type: numeric ──────────────────────────────────────────────────────
#>    skim_vari…¹ n_mis…² compl…³    mean      sd    p0    p25    p50    p75   p100
#>  1 mpg               0       1  20.1     6.03  10.4   15.4   19.2   22.8   33.9 
#>  2 cyl               0       1   6.19    1.79   4      4      6      8      8   
#>  3 disp              0       1 231.    124.    71.1  121.   196.   326    472   
#>  4 hp                0       1 147.     68.6   52     96.5  123    180    335   
#>  5 drat              0       1   3.60    0.535  2.76   3.08   3.70   3.92   4.93
#>  6 wt                0       1   3.22    0.978  1.51   2.58   3.32   3.61   5.42
#>  7 qsec              0       1  17.8     1.79  14.5   16.9   17.7   18.9   22.9 
#>  8 vs                0       1   0.438   0.504  0      0      0      1      1   
#>  9 am                0       1   0.406   0.499  0      0      0      1      1   
#> 10 gear              0       1   3.69    0.738  3      3      4      4      5   
#> 11 carb              0       1   2.81    1.62   1      2      2      4      8   
#> # … with 1 more variable: hist <chr>, and abbreviated variable names
#> #   ¹​skim_variable, ²​n_missing, ³​complete_rate

Created on 2022-10-15 with reprex v2.0.2

Session info ``` r sessionInfo() #> R version 4.2.0 (2022-04-22 ucrt) #> Platform: x86_64-w64-mingw32/x64 (64-bit) #> Running under: Windows 10 x64 (build 19044) #> #> Matrix products: default #> #> locale: #> [1] LC_COLLATE=Czech_Czechia.utf8 LC_CTYPE=Czech_Czechia.utf8 #> [3] LC_MONETARY=Czech_Czechia.utf8 LC_NUMERIC=C #> [5] LC_TIME=Czech_Czechia.utf8 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] skimr_2.1.4 #> #> loaded via a namespace (and not attached): #> [1] pillar_1.8.1 compiler_4.2.0 highr_0.9 base64enc_0.1-3 #> [5] R.methodsS3_1.8.2 R.utils_2.12.0 tools_4.2.0 digest_0.6.29 #> [9] jsonlite_1.8.0 evaluate_0.16 lifecycle_1.0.1 tibble_3.1.8 #> [13] R.cache_0.16.0 pkgconfig_2.0.3 rlang_1.0.4 reprex_2.0.2 #> [17] cli_3.3.0 rstudioapi_0.14 yaml_2.3.5 xfun_0.32 #> [21] fastmap_1.1.0 repr_1.1.4 withr_2.5.0 styler_1.7.0 #> [25] stringr_1.4.0 dplyr_1.0.10 knitr_1.40 generics_0.1.3 #> [29] fs_1.5.2 vctrs_0.4.1 tidyselect_1.1.2 glue_1.6.2 #> [33] R6_2.5.1 fansi_1.0.3 rmarkdown_2.17 tidyr_1.2.0 #> [37] purrr_0.3.4 magrittr_2.0.3 ellipsis_0.3.2 htmltools_0.5.3 #> [41] utf8_1.2.2 stringi_1.7.8 R.oo_1.25.0 ```
michaelquinn32 commented 2 years ago

Hi Michal!

Sorry about the issue, but I cannot reproduce it.

It appears that there is a bug around returning an invisible() value, but I don't really understand it past that.

Does it still appear after updating R or calling update.packages(ask = FALSE)?

Best wishes, Michael

library(skimr)
skimmed <- skim(mtcars)
print(skimmed, include_summary = FALSE)
#> 
#> ── Variable type: numeric ──────────────────────────────────────────────────────
#>    skim_variable n_missing complete_rate    mean      sd    p0    p25    p50
#>  1 mpg                   0             1  20.1     6.03  10.4   15.4   19.2 
#>  2 cyl                   0             1   6.19    1.79   4      4      6   
#>  3 disp                  0             1 231.    124.    71.1  121.   196.  
#>  4 hp                    0             1 147.     68.6   52     96.5  123   
#>  5 drat                  0             1   3.60    0.535  2.76   3.08   3.70
#>  6 wt                    0             1   3.22    0.978  1.51   2.58   3.32
#>  7 qsec                  0             1  17.8     1.79  14.5   16.9   17.7 
#>  8 vs                    0             1   0.438   0.504  0      0      0   
#>  9 am                    0             1   0.406   0.499  0      0      0   
#> 10 gear                  0             1   3.69    0.738  3      3      4   
#> 11 carb                  0             1   2.81    1.62   1      2      2   
#>       p75   p100 hist 
#>  1  22.8   33.9  ▃▇▅▁▂
#>  2   8      8    ▆▁▃▁▇
#>  3 326    472    ▇▃▃▃▂
#>  4 180    335    ▇▇▆▃▁
#>  5   3.92   4.93 ▇▃▇▅▁
#>  6   3.61   5.42 ▃▃▇▁▂
#>  7  18.9   22.9  ▃▇▇▂▁
#>  8   1      1    ▇▁▁▁▆
#>  9   1      1    ▇▁▁▁▆
#> 10   4      5    ▇▁▆▁▂
#> 11   4      8    ▇▂▅▁▁

Created on 2022-10-18 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ────────────────────────────────────── #> setting value #> version R version 4.2.1 (2022-06-23) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Etc/UTC #> date 2022-10-18 #> pandoc 2.9.2.1 @ /usr/bin/ (via rmarkdown) #> #> ─ Packages ──────────────────────────────────────── #> package * version date (UTC) lib source #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.2.1) #> cli 3.4.1 2022-09-23 [1] CRAN (R 4.2.1) #> digest 0.6.30 2022-10-18 [1] CRAN (R 4.2.1) #> dplyr 1.0.10 2022-09-01 [1] CRAN (R 4.2.1) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.2.1) #> evaluate 0.17 2022-10-07 [1] CRAN (R 4.2.1) #> fansi 1.0.3 2022-03-24 [1] CRAN (R 4.2.1) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.2.1) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.2.1) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.2.1) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.2.1) #> highr 0.9 2021-04-16 [1] CRAN (R 4.2.1) #> htmltools 0.5.3 2022-07-18 [1] CRAN (R 4.2.1) #> jsonlite 1.8.2 2022-10-02 [1] CRAN (R 4.2.1) #> knitr 1.40 2022-08-24 [1] CRAN (R 4.2.1) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.2.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.2.1) #> pillar 1.8.1 2022-08-19 [1] CRAN (R 4.2.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.2.1) #> purrr 0.3.5 2022-10-06 [1] CRAN (R 4.2.1) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.2.1) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.2.1) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.2.1) #> R.utils 2.12.0 2022-06-28 [1] CRAN (R 4.2.1) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.2.1) #> repr 1.1.4 2022-01-04 [1] CRAN (R 4.2.1) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.2.1) #> rlang 1.0.6 2022-09-24 [1] CRAN (R 4.2.1) #> rmarkdown 2.17 2022-10-07 [1] CRAN (R 4.2.1) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.2.1) #> skimr * 2.1.4 2022-10-18 [1] local #> stringi 1.7.8 2022-07-11 [1] CRAN (R 4.2.1) #> stringr 1.4.1 2022-08-20 [1] CRAN (R 4.2.1) #> styler 1.7.0 2022-03-13 [1] CRAN (R 4.2.1) #> tibble 3.1.8 2022-07-22 [1] CRAN (R 4.2.1) #> tidyr 1.2.1 2022-09-08 [1] CRAN (R 4.2.1) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.2.1) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.2.1) #> vctrs 0.4.2 2022-09-29 [1] CRAN (R 4.2.1) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.2.1) #> xfun 0.33 2022-09-12 [1] CRAN (R 4.2.1) #> yaml 2.3.6 2022-10-18 [1] CRAN (R 4.2.1) #> #> ──────────────────────────────────────────── ```
MichalLauer commented 2 years ago

Hi Michael,

I called update.packages(ask = FALSE) but skimr didn't update.

Strangely, after creating a custom function and ending it with invisible(), it works now as expected

library(skimr)
#> Warning: package 'skimr' was built under R version 4.2.1
skimmed <- skim(mtcars)
call <- function(x) {
  print(x, include_summary = FALSE)
  invisible()
}
call(skimmed)
#> 
#> ── Variable type: numeric ──────────────────────────────────────────────────────
#>    skim_variable n_missing complete_rate    mean      sd    p0    p25    p50
#>  1 mpg                   0             1  20.1     6.03  10.4   15.4   19.2 
#>  2 cyl                   0             1   6.19    1.79   4      4      6   
#>  3 disp                  0             1 231.    124.    71.1  121.   196.  
#>  4 hp                    0             1 147.     68.6   52     96.5  123   
#>  5 drat                  0             1   3.60    0.535  2.76   3.08   3.70
#>  6 wt                    0             1   3.22    0.978  1.51   2.58   3.32
#>  7 qsec                  0             1  17.8     1.79  14.5   16.9   17.7 
#>  8 vs                    0             1   0.438   0.504  0      0      0   
#>  9 am                    0             1   0.406   0.499  0      0      0   
#> 10 gear                  0             1   3.69    0.738  3      3      4   
#> 11 carb                  0             1   2.81    1.62   1      2      2   
#>       p75   p100 hist 
#>  1  22.8   33.9  ▃▇▅▁▂
#>  2   8      8    ▆▁▃▁▇
#>  3 326    472    ▇▃▃▃▂
#>  4 180    335    ▇▇▆▃▁
#>  5   3.92   4.93 ▇▃▇▅▁
#>  6   3.61   5.42 ▃▃▇▁▂
#>  7  18.9   22.9  ▃▇▇▂▁
#>  8   1      1    ▇▁▁▁▆
#>  9   1      1    ▇▁▁▁▆
#> 10   4      5    ▇▁▆▁▂
#> 11   4      8    ▇▂▅▁▁

Created on 2022-10-18 with reprex v2.0.2

Session info ``` r sessionInfo() #> R version 4.2.0 (2022-04-22 ucrt) #> Platform: x86_64-w64-mingw32/x64 (64-bit) #> Running under: Windows 10 x64 (build 19044) #> #> Matrix products: default #> #> locale: #> [1] LC_COLLATE=Czech_Czechia.utf8 LC_CTYPE=Czech_Czechia.utf8 #> [3] LC_MONETARY=Czech_Czechia.utf8 LC_NUMERIC=C #> [5] LC_TIME=Czech_Czechia.utf8 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> other attached packages: #> [1] skimr_2.1.4 #> #> loaded via a namespace (and not attached): #> [1] pillar_1.8.1 compiler_4.2.0 highr_0.9 base64enc_0.1-3 #> [5] R.methodsS3_1.8.2 R.utils_2.12.0 tools_4.2.0 digest_0.6.29 #> [9] jsonlite_1.8.2 evaluate_0.17 lifecycle_1.0.3 tibble_3.1.8 #> [13] R.cache_0.16.0 pkgconfig_2.0.3 rlang_1.0.6 reprex_2.0.2 #> [17] cli_3.4.1 rstudioapi_0.14 yaml_2.3.5 xfun_0.33 #> [21] fastmap_1.1.0 repr_1.1.4 withr_2.5.0 styler_1.7.0 #> [25] stringr_1.4.1 dplyr_1.0.10 knitr_1.40 generics_0.1.3 #> [29] fs_1.5.2 vctrs_0.4.2 tidyselect_1.2.0 glue_1.6.2 #> [33] R6_2.5.1 fansi_1.0.3 rmarkdown_2.17 tidyr_1.2.1 #> [37] purrr_0.3.5 magrittr_2.0.3 ellipsis_0.3.2 htmltools_0.5.3 #> [41] utf8_1.2.2 stringi_1.7.8 R.oo_1.25.0 ```

As the issue is now fixed, I'm closing this thread. Thanks for your help!