Closed ddsjoberg closed 2 years ago
Thanks so much!
And oof, thanks for asking about this - I am still adding my tests and I'll make sure to include this scenario 🙃
I've added a lightweight "blank return" if a NA or NULL is for that row.
Using gtExtras
v 0.2.17, with your example (slightly modified to include a NA
and a NULL
).
It now returns the below without a warning/error:
library(tidyverse)
library(gt)
library(gtExtras)
input_data <- mtcars %>%
dplyr::group_by(cyl) %>%
# must end up with list of data for each row in the input dataframe
dplyr::summarize(mpg_data = list(mpg), .groups = "drop") %>%
dplyr::mutate(
mpg_data = list(mpg_data[[1]], list(NA), list(NULL))
)
input_data %>%
gt() %>%
gt_sparkline(mpg_data) %>%
gtsave("ex.png")
Created on 2021-10-11 by the reprex package (v2.0.1)
Ahhhh, gorgeous! Thank you @jthomasmock !!!
Hello Again @jthomasmock !
Thank you for this update! It's been great! I noticed that this code works flawlessly for sparkline and histogram, but errors with type = "density"
library(tidyverse)
library(gt)
library(gtExtras)
input_data <- mtcars %>%
dplyr::group_by(cyl) %>%
# must end up with list of data for each row in the input dataframe
dplyr::summarize(mpg_data = list(mpg), .groups = "drop") %>%
dplyr::mutate(
mpg_data = list(mpg_data[[1]], list(NA), list(NULL))
)
input_data %>%
gt::gt() %>%
gtExtras::gt_sparkline(mpg_data, type = "density")
#> Error in quantile.default(as.numeric(x), c(0.25, 0.75), na.rm = na.rm, : missing values and NaN's not allowed if 'na.rm' is FALSE
Created on 2021-10-18 by the reprex package (v2.0.1)
Thanks for heads up! I've added another internal early return()
/missing data handling and added gt_sparkline
+ missing data handling to tests. Working as seen below in latest package version.
library(gt)
library(gtExtras)
input_data <- mtcars %>%
dplyr::group_by(cyl) %>%
# must end up with list of data for each row in the input dataframe
dplyr::summarize(mpg_data = list(mpg), .groups = "drop") %>%
dplyr::mutate(
mpg_data = list(mpg_data[[1]], list(NA), list(NULL))
)
# Spark -------------------------------------------------------------------
input_data %>%
gt::gt() %>%
gt_sparkline(.data$mpg_data, type = "sparkline") %>%
gt::gtsave("temp-spark.png")
# Histogram ---------------------------------------------------------------
input_data %>%
gt::gt() %>%
gt_sparkline(.data$mpg_data, type = "histogram") %>%
gt::gtsave("temp-hist.png")
# Density -----------------------------------------------------------------
input_data %>%
gt::gt() %>%
gt_sparkline(.data$mpg_data, type = "density") %>%
gt::gtsave("temp-dens.png")
Created on 2021-10-18 by the reprex package (v2.0.1)
you are amazingly quick! thank you! looks great!
The gtsummary + gtExtras + sparkline table looks super cute 😍
trial %>%
select(age, marker) %>%
tbl_summary(missing = "no") %>%
add_sparkline()
http://www.danieldsjoberg.com/bstfun/reference/add_sparkline.html
Glad it's working in gtsummary
now!
Hello! gtExtras is so cool and cute!
How do you feel about allowing a missing row in
gt_sparline()
? For example, in the example below, the second row is all missing, and I would like to see the image in the first and third rows and a blank second row. (I get an error iflist(NA)
is replaced withNULL
.)What do you think?
Created on 2021-10-10 by the reprex package (v2.0.0)