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

Handling of NULL grobs in gtable_add_grob() #80

Open
paleolimbot opened this issue May 3, 2019 · 0 comments
Open

Handling of NULL grobs in gtable_add_grob() #80

paleolimbot opened this issue May 3, 2019 · 0 comments

Comments

@paleolimbot
Copy link

I ran across this while working on tidyverse/ggplot2#2810. It seems as though the gtable $grobs element is assumed to be a list of grobs, as the print() and grid.draw() methods fail if any of these elements are NULL. However, they are not checked by gtable_add_grob() when grobs is a list. This makes it difficult to debug, as the errors are delayed until render time.

gt <- gtable::gtable(
  widths = grid::unit(1, "null"), 
  heights = grid::unit(1, "null")
)

# correctly identified as not a grob
gtable::gtable_add_grob(gt, NULL, 1, 1, 1, 1)
#> Error: grobs must either be a single grob or a list of grobs

# creating this gtable is fine
gt_null <- gtable::gtable_add_grob(gt, list(NULL), 1, 1, 1, 1)

# ...but nothing can be done with it
print(gt_null)
#> TableGrob (1 x 1) "layout": 1 grobs
#> Error in vapply(x$grobs, as.character, character(1)): values must be length 1,
#>  but FUN(X[[1]]) result is length 0
grid::grid.draw(gt_null)
#> Error in gList(structure(list(wrapvp = structure(list(x = structure(0.5, class = "unit", valid.unit = 0L, unit = "npc"), : only 'grobs' allowed in "gList"

Created on 2019-05-03 by the reprex package (v0.2.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

1 participant