wilkelab / gridtext

Improved text rendering support for grid graphics in R
https://wilkelab.org/gridtext
Other
96 stars 17 forks source link

Add option to ignore unimplemented tags instead of throwing an error #32

Open ktrask opened 1 year ago

ktrask commented 1 year ago

I encountered a the error message Error: gridtext has encountered a tag that isn't supported yet: <code> while not adding this <code> tag anywhere. It came because sometimes ggplot adds backticks in some cases in axis labels. And the backticks are evaluated by the markdown package to <code>-tags. Also I cannot control all the labels that are used in the software I want to use gridtext/ggtext in, I wanted the option to prevent gridtext to stop on unknown tags. So I added it.

Example:

library(grid)
library(gridtext)
options(gridtext.stop_if_tag_is_unimplemented=FALSE)
g <- textbox_grob(
  "Test `backticks`",
  x = unit(0.5, "npc"), y = unit(0.7, "npc"),
  gp = gpar(fontsize = 15),
  box_gp = gpar(col = "black", fill = "lightcyan1"),
  r = unit(5, "pt"),
  padding = unit(c(10, 10, 10, 10), "pt"),
  margin = unit(c(0, 10, 0, 10), "pt")
)
grid.newpage()
grid.draw(g)
clauswilke commented 1 year ago

That seems a bit over-engineered. I think it's fine to just replace the error with a warning. The main reason why I put the error there was I didn't want hundreds of bug reports that certain things don't render correctly when there was never any support of those features to begin with. But a warning communicates that just the same. (In my experience from teaching R to hundreds of undergrads, they typically think a warning is an error anyways.)

ktrask commented 1 year ago

Thank you for the feedback!

I have changed the code accordingly and just changed the error to a warning about unimplemented tags.