You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
R partial string matching can have unexpected results when theme elements are missing #2724
This is related to #2723, but really a distinct issue that I wanted to record separately. If a theme element is missing then R may decide to return a different one whose name partially matches. This can have unexpected results.
Isn't that the standard R behaviour? $ for interactive use (convenient but also dangerous partial matching), and [[ for programatic use (verbose but safe).
I could definitely be convinced otherwise, but I think that $ should probably never be used on a theme. Instead, calc_element() should be used, as it knows about element inheritance. Any code that isn't internal to the themes that uses $ is usually calculating its own inheritance (or assuming none), which could easily become misaligned with the inheritance defined in the theme code.
I agree, and we should move in that direction whenever we can. We're not quite there yet, though, in particular in the guide code which is a mess. Example:
Activity
clauswilke commentedon Jun 29, 2018
As proposed by @karawoo here, a solution would be to write
t[["legend.box"]]instead oft$legend.box.I was wondering whether this would affect performance, and it appears to be as good as or better:
So we could consider making this a style guide throughout ggplot2, for more bug-free code at possibly somewhat improved performance.
baptiste commentedon Jun 29, 2018
Isn't that the standard R behaviour?
$for interactive use (convenient but also dangerous partial matching), and[[for programatic use (verbose but safe).hadley commentedon Jun 29, 2018
We could also override
$.themewhich would require considerably fewer changes to existing code.paleolimbot commentedon Jun 25, 2019
I could definitely be convinced otherwise, but I think that
$should probably never be used on atheme. Instead,calc_element()should be used, as it knows about element inheritance. Any code that isn't internal to the themes that uses$is usually calculating its own inheritance (or assuming none), which could easily become misaligned with the inheritance defined in the theme code.clauswilke commentedon Jun 25, 2019
I agree, and we should move in that direction whenever we can. We're not quite there yet, though, in particular in the guide code which is a mess. Example:
ggplot2/R/guide-colorbar.r
Lines 365 to 369 in e2bdf85
In any case, this would be a good topic for the missing vignette on internal programming guidelines. 😄