ropensci / skimr

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

Error when a group is all infinite #745

Open lazappi opened 1 month ago

lazappi commented 1 month ago

Hi

I just came across this error when grouping results in a variable having only infinite values. It seems to be coming from a {glue} call but I suspect the root error may be something to do with calculating statistics and then processing that error message.

library(dplyr)
library(skimr)

df <- data.frame(group = c("A", "B"), a = c(1, Inf))

# Skimming the whole data frame works (with a  warning)
skim(df)
#> Warning: There was 1 warning in `dplyr::summarize()`.
#> ℹ In argument: `dplyr::across(tidyselect::any_of(variable_names),
#>   mangled_skimmers$funs)`.
#> ℹ In group 0: .
#> Caused by warning:
#> ! There was 1 warning in `dplyr::summarize()`.
#> ℹ In argument: `dplyr::across(tidyselect::any_of(variable_names),
#>   mangled_skimmers$funs)`.
#> Caused by warning in `inline_hist()`:
#> ! Variable contains Inf or -Inf value(s) that were converted to NA.
Name df
Number of rows 2
Number of columns 2
_______________________
Column type frequency:
character 1
numeric 1
________________________
Group variables None

Data summary

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
group 0 1 1 1 0 2 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
a 0 1 Inf NaN 1 Inf Inf Inf Inf ▁▁▇▁▁
# Grouping then skimming gives an error
df |> group_by(group) |> skim()
#> Error:
#> ! Failed to evaluate glue component {label}
#> Caused by error in `vapply()`:
#> ! values must be length 1,
#>  but FUN(X[[1]]) result is length 0

Created on 2024-07-22 with reprex v2.1.1

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.4.0 (2024-04-24) #> os macOS Sonoma 14.5 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Europe/Berlin #> date 2024-07-22 #> pandoc 3.1.11 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> ! package * version date (UTC) lib source #> P base64enc 0.1-3 2015-07-28 [?] CRAN (R 4.4.0) #> P cli 3.6.3 2024-06-21 [?] CRAN (R 4.4.0) #> P digest 0.6.36 2024-06-23 [?] CRAN (R 4.4.0) #> P dplyr * 1.1.4 2023-11-17 [?] CRAN (R 4.4.0) #> P evaluate 0.24.0 2024-06-10 [?] CRAN (R 4.4.0) #> P fansi 1.0.6 2023-12-08 [?] CRAN (R 4.4.0) #> P fastmap 1.2.0 2024-05-15 [?] CRAN (R 4.4.0) #> P fs 1.6.4 2024-04-25 [?] CRAN (R 4.4.0) #> P generics 0.1.3 2022-07-05 [?] CRAN (R 4.4.0) #> P glue 1.7.0 2024-01-09 [?] CRAN (R 4.4.0) #> P htmltools 0.5.8.1 2024-04-04 [?] CRAN (R 4.4.0) #> P jsonlite 1.8.8 2023-12-04 [?] CRAN (R 4.4.0) #> P knitr 1.48 2024-07-07 [?] CRAN (R 4.4.0) #> P lifecycle 1.0.4 2023-11-07 [?] CRAN (R 4.4.0) #> P magrittr 2.0.3 2022-03-30 [?] CRAN (R 4.4.0) #> P pillar 1.9.0 2023-03-22 [?] CRAN (R 4.4.0) #> P pkgconfig 2.0.3 2019-09-22 [?] CRAN (R 4.4.0) #> P purrr 1.0.2 2023-08-10 [?] CRAN (R 4.4.0) #> P R6 2.5.1 2021-08-19 [?] CRAN (R 4.4.0) #> P repr 1.1.7 2024-03-22 [?] CRAN (R 4.4.0) #> P reprex 2.1.1 2024-07-06 [?] CRAN (R 4.4.0) #> P rlang 1.1.4 2024-06-04 [?] CRAN (R 4.4.0) #> P rmarkdown 2.27 2024-05-17 [?] CRAN (R 4.4.0) #> P rstudioapi 0.16.0 2024-03-24 [?] CRAN (R 4.4.0) #> P sessioninfo 1.2.2 2021-12-06 [?] CRAN (R 4.4.0) #> P skimr * 2.1.5 2022-12-23 [?] CRAN (R 4.4.0) #> P stringi 1.8.4 2024-05-06 [?] CRAN (R 4.4.0) #> P stringr 1.5.1 2023-11-14 [?] CRAN (R 4.4.0) #> P tibble 3.2.1 2023-03-20 [?] CRAN (R 4.4.0) #> P tidyr 1.3.1 2024-01-24 [?] CRAN (R 4.4.0) #> P tidyselect 1.2.1 2024-03-11 [?] CRAN (R 4.4.0) #> P utf8 1.2.4 2023-10-22 [?] CRAN (R 4.4.0) #> P vctrs 0.6.5 2023-12-01 [?] CRAN (R 4.4.0) #> P withr 3.0.0 2024-01-16 [?] CRAN (R 4.4.0) #> P xfun 0.45 2024-06-16 [?] CRAN (R 4.4.0) #> P yaml 2.3.9 2024-07-05 [?] CRAN (R 4.4.0) #> #> [1] /Users/luke.zappia/Documents/Projects/20240710-NewScreenings-MyeloidLuminex/renv/library/macos/R-4.4/aarch64-apple-darwin20 #> [2] /Users/luke.zappia/Library/Caches/org.R-project.R/R/renv/sandbox/macos/R-4.4/aarch64-apple-darwin20/f7156815 #> [3] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library #> #> P ── Loaded and on-disk path mismatch. #> #> ────────────────────────────────────────────────────────────────────────────── ```