jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

`NA` values break `gt_plt_conf_int()` #52

Closed jmbarbone closed 2 years ago

jmbarbone commented 2 years ago

Using the example from ?gt_plt_conf_int with NA values added.

library(gtExtras)
packageVersion("gtExtras")
#> [1] '0.4.0'

dplyr::tibble(
  mean = c(12, 10, NA), 
  ci1 = c(8, 5, NA),
  ci2 = c(16, 15, NA),
  ci_plot = c(12, 10, NA)
) %>%
  gt::gt() %>%
  gt_plt_conf_int(
    ci_plot,
    c(ci1, ci2),
    palette = c("red", "lightgrey", "black", "red")
  )
#> Error in if (zero_range(range)) zero_width else diff(range): missing value where TRUE/FALSE needed

# might need to wrap with !isFALSE
scales::zero_range(range(NA))
#> [1] NA

Created on 2022-06-08 by the reprex package (v2.0.1)

jthomasmock commented 2 years ago

Thanks for report/reprex @jmbarbone !

I would recommend omitting NA values (ie na.omit()) for now but I have a fix in local dev version and am doing more testing.

The function has a min/max call and adding na.rm=TRUE solves for this problem.