insightsengineering / insightsengineering/teal.widgets

`resolve_ggplot2_args`: assertion fails even though argument is legitimate

Open
#108 1 comment 0 reactions 0 assignees View on GitHub
core
Dominant language
R
Stars
6
Forks
8
PR merge metrics
No merged PRs in 30d

Description

### What happened?

Working with `teal.modules.general::tm_variable_browser`, I have a plotting function that generates `ggplot`s 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.](https://github.com/tidyverse/ggplot2/issues/5054)

_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

- [X] I agree to follow this project's Code of Conduct.

### Contribution Guidelines

- [X] I agree to follow this project's Contribution Guidelines.

### Security Policy

- [X] I agree to follow this project's Security Policy.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.