Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gt_theme_guardian error when nrow == 0 #41

Closed
mbjohnsonmn opened this issue Mar 22, 2022 · 4 comments
Closed

gt_theme_guardian error when nrow == 0 #41

mbjohnsonmn opened this issue Mar 22, 2022 · 4 comments

Comments

@mbjohnsonmn
Copy link

Here is the reprex, from the documented example:

library(gt)
themed_tab <- head(mtcars) %>%
filter(vs == 2) %>%
gt() %>%
gt_theme_guardian()
Error: The following row indices do not exist in the data: 1

gt_theme_nytimes and others do not produce this error.

@mbjohnsonmn mbjohnsonmn changed the title gt_theme_guardian error when nrow = 0 gt_theme_guardian error when nrow == 0 Mar 28, 2022
@mbjohnsonmn
Copy link
Author

I found this is the code in gt_theme_guardian() that is producing the error:

tab_style(
  style = cell_borders(
    sides = "top", color = "white", weight = px(0)
  ),
  locations = cells_body(rows = 1)
)

Since weight is set to px(0) I am not sure what this is for, but in any case was able to eliminate the error by commenting this out in a local copy. I am new to git and github so haven't worked out pull requests, yet, but I am working on it. ;-}

@jthomasmock
Copy link
Owner

Howdy, thanks for the report!

I'm slightly confused, are you intending to create tables with no data in them?

In short, the px(0) is necessary to remove the border formatting between the cell_label and the first row of data. While I could in theory add additional logic to "protect" against empty tables, I'm not following why you want a table without any rows/data?

Other themes don't have that specific set of code as they aren't changing the border between the label/cell body.

@mbjohnsonmn
Copy link
Author

mbjohnsonmn commented Mar 29, 2022 via email

@jthomasmock
Copy link
Owner

Thanks for the note! I've updated gt_theme_guardian() to allow for zero-length tables.

In latest version on GH, see:

library(gt)
library(gtExtras)

head(mtcars) %>%
  dplyr::filter(vs == 2) %>%
  gt() %>%
  gt_theme_guardian() %>% 
  gtsave("test.png")

Created on 2022-03-29 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants