-
Notifications
You must be signed in to change notification settings - Fork 2.1k
R partial string matching can have unexpected results when theme elements are missing #2724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As proposed by @karawoo here, a solution would be to write I was wondering whether this would affect performance, and it appears to be as good as or better: library(ggplot2)
t <- theme_void() + theme(legend.box.background = element_rect(fill = "gray80"))
microbenchmark::microbenchmark(
t$legend.box,
t[["legend.box"]]
)
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> t$legend.box 1.257 1.2810 1.51647 1.2965 1.3240 19.462 100
#> t[["legend.box"]] 1.107 1.1355 1.25123 1.1620 1.1855 8.158 100 So we could consider making this a style guide throughout ggplot2, for more bug-free code at possibly somewhat improved performance. |
Isn't that the standard R behaviour? |
We could also override |
I could definitely be convinced otherwise, but I think that |
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: Lines 365 to 369 in e2bdf85
In any case, this would be a good topic for the missing vignette on internal programming guidelines. 😄 |
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.
Created on 2018-06-28 by the reprex package (v0.2.0).
The text was updated successfully, but these errors were encountered: