insightsengineering / teal.widgets

shiny widgets for teal applications
https://insightsengineering.github.io/teal.widgets/
Other
4 stars 6 forks source link

`resolve_ggplot2_args`: assertion fails even though argument is legitimate #108

Open chlebowa opened 1 year ago

chlebowa commented 1 year ago

What happened?

Working with teal.modules.general::tm_variable_browser, I have a plotting function that generates ggplots and accepts a ggplot2_args object as argument. I want the resulting plots to have one of the ggplot2 themes.

Within tm_variable_browser_srv I run

user_theme <- ggplot2::theme_grey()
args_all <- resolve_ggplot2_args(
  user_default = ggplot2_args(theme = user_theme),
  module_plot = ggplot2_args # argument passed from the caller frame
)

foo(..., ggplot2_agrs = args_all)

which fails:

Error in teal.widgets::ggplot2_args(theme = user_theme) : 
  Assertion on 'names(theme)' failed: Must be a subset of {'line','rect','text','title','aspect.ratio','axis.title','axis.title.x','axis.title.x.top','axis.title.x.bottom','axis.title.y','axis.title.y.left','axis.title.y.right','axis.text','axis.text.x','axis.text.x.top','axis.text.x.bottom','axis.text.y','axis.text.y.left','axis.text.y.right','axis.ticks','axis.ticks.x','axis.ticks.x.top','axis.ticks.x.bottom','axis.ticks.y','axis.ticks.y.left','axis.ticks.y.right','axis.ticks.length','axis.ticks.length.x','axis.ticks.length.x.top','axis.ticks.length.x.bottom','axis.ticks.length.y','axis.ticks.length.y.left','axis.ticks.length.y.right','axis.line','axis.line.x','axis.line.x.top','axis.line.x.bottom','axis.line.y','axis.line.y.left','axis.line.y.right','legend.background','legend.margin','legend.spacing','legend.spacing.x','legend.spacing.y','legend.key','legend.key.size','legend.key.height','legend.key.width','legend.text','legend.text.align','legend.title','legend.title.align'

The assertion in ggplot2_args tests the names of the list passed to the theme argument against the formal arguments of ggplot2::theme. However, ggplot2::theme has a ... argument, so features not covered by formal arguments can be specified.

Currently this is the case with 7 of 9 themes and always the culprit is the strip.text.y.left field.

An issue was raised with the ggplot2 team.

NOTE: In this case the theme cannot be supplied with

args_parsed <- parse_ggplot2_args(args_all, "gray")
foo(..., ggplot2_args = args_parsed)

because parse_ggplot2_args returns a list of calls and not a ggplot2_args object, which the plotting function expects.

sessionInfo()

No response

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

chlebowa commented 1 year ago

When this is resolved, update the "temporary fix" section in teal.modules.general::tm_variable_browser.