-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Warn on the use of ..var..
and stat(var)
#4950
Warn on the use of ..var..
and stat(var)
#4950
Conversation
I think this is sensible - @hadley do you have any issues with this? Also, @yutannihilation is there a reason why you are not using the |
The main reason is that I just copied the code from here. Actually, I'm not sure when to use Lines 132 to 136 in 7ac55dd
|
Ah, I see... The reason why we don't use it in the example above is that the auto-generation of text doesn't really capture what is happening due to the special syntax of ggplot2 In general we will always use the lifecycle functions for deprecations. If they have been superseded I don't think we should issue any warning at all since that means they are still proper syntax I guess the question then is: Do we want to formally deprecate them? If so we should use lifecycle |
I see, thanks for the explanation!
Makes sense. In my opinion, we should deprecate them then. A superseded function or syntax is preserved because it might not be very easy for all users to replace it with the superseder one. But, in this case, all |
I think it's probably ok to deprecate them; the warning is only once every 8 hours so it's not terribly annoying. Note that in dev lifecycle you can use |
Thanks! Then, let's move forward. But, I found Let me raise one more question. If the intention is to mimic the behaviour of |
See https://lifecycle.r-lib.org/dev/articles/communicate.html#anything-else I’d also recommend using |
@yutannihilation you can easily use lifecycle for |
@hadley @thomasp85 |
If you don't mind, could you also update the line size deprecation to use the new lifecycle feature? |
Sure! |
devtools::load_all("~/GitHub/ggplot2/")
#> ℹ Loading ggplot2
p <- ggplot(data.frame(), aes(..x.., stat(y)))
b <- ggplot_build(p)
#> Warning: The dot-dot notation (`..var..`) was deprecated in ggplot2 3.4.0.
#> Please use `after_stat()` instead.
#> Warning: `stat()` was deprecated in ggplot2 3.4.0.
#> Please use `after_stat()` instead. Created on 2022-08-24 with reprex v2.0.2 |
R/aes-evaluation.r
Outdated
is_dotted_var(as.character(x)) | ||
res <- is_dotted_var(as.character(x)) | ||
if (res && warn) { | ||
# TODO: if we want to set always = TRUE, we probably need some mechanism |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove this comment; we're still some time away from setting always = TRUE
, if we ever do so. This is a very old feature, so I think the deprecation needs to be quite mild.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
p <- ggplot(pts) | ||
expect_warning( | ||
expect_identical(grob_xy_length(p + aes(size = size)), c(1L, 1L)), | ||
expect_identical(grob_xy_length(p + geom_sf(aes(size = size))), c(1L, 1L)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed a tweak here because of this issue: #4960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a snapshot test that shows both new warnings?
R/aes-evaluation.r
Outdated
is_dotted_var(as.character(x)) | ||
res <- is_dotted_var(as.character(x)) | ||
if (res && warn) { | ||
lifecycle::deprecate_warn("3.4.0", I("The dot-dot notation (`..var..`)"), "after_stat()") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we interpolate the variable name in to ..{{var}}..
and after_stat({var}})
? (assuming var <- as.character(x))
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean this is supposed to work...?
var <- "foo"
lifecycle::deprecate_warn("3.4.0", "a()", "b({{var}})")
#> Error in `as_string()`:
#> ! Can't convert a call to a string.
#> Backtrace:
#> ▆
#> 1. └─lifecycle::deprecate_warn("3.4.0", "a()", "b({{var}})")
#> 2. ├─id %||% msg
#> 3. └─lifecycle:::lifecycle_message(...)
#> 4. └─lifecycle:::spec(with, NULL, signaller)
#> 5. └─lifecycle:::spec_arg(what$call, signaller = signaller)
#> 6. └─rlang::as_string(node_car(arg))
#> 7. └─rlang:::abort_coercion(x, "a string")
#> 8. └─rlang::abort(msg, call = call)
Created on 2022-08-25 with reprex v2.0.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, you’ll need to glue/paste yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Thanks for the suggestion anyway!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Thanks! @thomasp85 |
LGTM |
Thanks! |
Fix #3693
Considering the wide use of them, now I feel it's a bit difficult to deprecate them. Still, I think it's a good idea to issue a non-warning message at least because we want to advertise
after_stat()
more.