@grantmcdermott and @etiennebacher,
Here’s a first attempt to resolve the tinytheme in a loop issue. The idea is:
- Whenever
tpar()sets a hook, we save that hook to the.tinyplotenvironment. - When
tinytheme()resets the theme viainit_tpar(), we retrieve the hooks from the.tinyplotenvironment and remove only the"before.plot.new"hooks that areidentical()to those.
Implementation notes:
- I copied the
set_hooks()andremove_hooks()functions from theevaluatepackage and made a few minor changes to them. That package is MIT and included a note at the top of the file. - To make it easier to retrieve variables from the
.tinyplotenvironment, I added aget_environment_variable()andset_environment_variable()functions.
The tests pass on my computer, and this seems to work.
I’m not exactly sure I know all the behaviors that were broken, so I’d appreciate if you could take this for a spin.
res <- evaluate::evaluate(function(){ library(tinyplot) for (thm in c("dark", "minimal")) { tinytheme(thm) tinyplot(I(Sepal.Length * 1e4) ~ Petal.Length | Species, data = iris) } }) sapply(res, class) #> [1] "source" "source" "recordedplot" "recordedplot" "recordedplot" #> [6] "recordedplot"