Skip to content

tinytheme: Safer hook handling #424

@vincentarelbundock

Description

@vincentarelbundock

There is a discussion on the evaluate repo about hook handling in tinytheme(). Moving here to discuss the tinyplot-specific issues, instead of polluting everyone's mentions in the other repo. Tag @grantmcdermott

The tinytheme() design uses a before.plot.new hook to set persistent theme parameters. In principle, hooks can be specified as a list, and many can be specified and applied sequentially before drawing the plot. However,

  1. Most of the time tinytheme() wants to reset parameters (i.e., delete existing hooks) to default values before applying its own.
  2. AFAICT, there is not a great mechanism in R to "tag" or "name" elements of the hook list, that would enable us to identify the tinyplot-specific hooks.

Because of 2, we cannot filter the hook list, that is, we cannot only remove those that we know for sure we have set. Instead, we call:

setHook("before.new.plot", NULL, "replace")

This removes ALL hooks, including some that might have been set by other packages, such as evaluate.

I don't remember all the details, but I do remember trying many alternatives to this when implementing. All had really fiddly edge cases, with theme elements not being reset and such. Frankly, I think this is above my pay grade, as I'm not that great with R graphics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions