darwin-eu-dev / PatientProfiles

https://darwin-eu-dev.github.io/PatientProfiles/
Apache License 2.0
6 stars 5 forks source link

estimate value `NA` when variable is empty for all estimates #674

Closed nmercadeb closed 1 month ago

nmercadeb commented 1 month ago

When all values of a variable are NA, most estimate functions return NA however min, max and mean don't and this results in warings, see reprex.

Agreed with @catalamarti and @edward-burn to output them as NA and avoid throwing the warnings.

dplyr::tibble(group = "N", var = c(NA, NA, NA) |> as.integer()) |> PatientProfiles::summariseResult(group = "group", estimates = c("min", "max", "mean", "median", "percentage", "q25")) |> dplyr::glimpse()
#> ℹ The following estimates will be computed:
#> • group: percentage
#> • var: min, max, mean, median, percentage, q25
#> ! Table is collected to memory as not all requested estimates are supported on
#>   the database side
#> → Start summary of data, at 2024-07-09 16:48:44
#> Warning: There were 2 warnings in `dplyr::summarise()`.
#> The first warning was:
#> ℹ In argument: `dplyr::across(...)`.
#> ℹ In group 1: `strata_id = 1`.
#> Caused by warning in `base::min()`:
#> ! no non-missing arguments to min; returning Inf
#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
#> ✔ Summary finished, at 2024-07-09 16:48:45
#> Rows: 9
#> Columns: 13
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1
#> $ cdm_name         <chr> "unknown", "unknown", "unknown", "unknown", "unknown"…
#> $ group_name       <chr> "group", "group", "group", "group", "group", "group",…
#> $ group_level      <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N"
#> $ strata_name      <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ strata_level     <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ variable_name    <chr> "number records", "group", "var", "var", "var", "var"…
#> $ variable_level   <chr> NA, "N", NA, NA, NA, NA, NA, NA, NA
#> $ estimate_name    <chr> "count", "percentage", "min", "max", "mean", "median"…
#> $ estimate_type    <chr> "integer", "percentage", "integer", "integer", "numer…
#> $ estimate_value   <chr> "3", "100", "Inf", "-Inf", "NaN", NA, "NaN", NA, "0"
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…

Created on 2024-07-09 with reprex v2.1.0