-
Notifications
You must be signed in to change notification settings - Fork 2k
-
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
Checking ...
#3196
Comments
And in all other functions that use |
Does this require us to replace all f1 <- function(..., title = "foo") {
ellipsis::check_dots_used()
list(..., title = title)
}
f2 <- function(..., title = "foo") {
ellipsis::check_dots_used()
rlang::list2(..., title = title)
}
f1(tile = "Title has a typo")
#> $tile
#> [1] "Title has a typo"
#>
#> $title
#> [1] "foo"
f2(tile = "Title has a typo")
#> Warning: Some components of ... were not used: tile
#> $tile
#> [1] "Title has a typo"
#>
#> $title
#> [1] "foo" Created on 2019-03-24 by the reprex package (v0.2.1) |
Hmm, I come to think we can do nothing for library(ggplot2)
labs <- function (..., title = waiver(), subtitle = waiver(), caption = waiver(),
tag = waiver()) {
ellipsis::check_dots_used()
args <- rlang::list2(..., title = title, subtitle = subtitle, caption = caption, tag = tag)
is_waive <- vapply(args, ggplot2:::is.waive, logical(1))
args <- args[!is_waive]
args <- args[!duplicated(names(args))]
args <- ggplot2:::rename_aes(args)
structure(args, class = "labels")
}
labs(tile = "Title has a typo")
#> Warning: Some components of ... were not used: tile
#> $tile
#> [1] "Title has a typo"
#>
#> attr(,"class")
#> [1] "labels"
labs(colour = "colour is a valid aesthetic")
#> Warning: Some components of ... were not used: colour
#> $colour
#> [1] "colour is a valid aesthetic"
#>
#> attr(,"class")
#> [1] "labels" Created on 2019-03-24 by the reprex package (v0.2.1) |
We could do something at build time if we really wants to because all named aesthetics is known there. Not sure it is worth it, though |
Thanks. For this particular issue, I agree it's build time if we do some verification. |
To clarify, this issue is a general discussion about checking
|
At least for For example, see Thus, I guess reordering of formals may also help users so that In this way, 1st to the 5th arguments of library(ggplot2)
library(scales)
scale_alpha_continuous2 <- continuous_scale
formals(scale_alpha_continuous2)[c(
"aesthetics", "scale_name", "palette", "range"
)] <-
alist("alpha", "alpha_c", rescale_pal(range), c(0.1, 1))
qplot(x=1:10, y=1:10, alpha = 1:10) +
scale_alpha_continuous2() Created on 2019-03-29 by the reprex package (v0.2.1) |
I do not think modifying formals is the right way to approach this problem. |
I too feel modifying formals might not be the direct answer here, but I think the point is that in some cases we don't really need |
A good next step on this issue would be to systematically survey all use of |
It's a bit too long for an issue comment, but I put a summary of all 217 uses (excluding s3 generics and methods) here: https://gist.github.com/paleolimbot/708effa39e67bb53f54f30499562587b |
I reviewed all exported functions using
Here is some code illustrating the issues: library(ggplot2)
# fortify doesn't warn
p <- ggplot(mpg, aes(displ, hwy, colour = drv), foo = "bar") +
geom_point() +
guides(
# deprecated_guide_args() doesn't warn
colour = guide_legend(non = "sense"),
# non existing aesthetics are silently accepted
foobar = "qux"
) +
facet_wrap(
~ year,
# labeller args are ignored
labeller = labeller(year = label_both, nonsense = label_value)
) +
labs(
alt = "my alt text",
# unknown labels are ignored
i_dont = "exist"
)
# Extra arguments are ignored
get_alt_text(p, hamspam = "green eggs")
#> [1] "my alt text" Created on 2024-08-06 with reprex v2.1.1 |
Following this twitter thread.
labs()
uses...
, but the name of the arguments are not checked, so this can lead to errors when passingtile =
instead oftitle
, or any other typo.It would be nice for the user to have at least a warning (or an error) here:
The text was updated successfully, but these errors were encountered: