Skip to content
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

Restore old guides in guides() #6167

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions R/guides-.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@
#' }
guides <- function(...) {
args <- list2(...)
if (length(args) > 0) {
if (is.list(args[[1]]) && !is.guide(args[[1]])) args <- args[[1]]
args <- rename_aes(args)
# If there are no guides do nothing
if (length(args) == 0) {
return(NULL)
}

if (is.list(args[[1]]) && !inherits(args[[1]], "guide")) args <- args[[1]]

Check warning on line 76 in R/guides-.R

View check run for this annotation

Codecov / codecov/patch

R/guides-.R#L76

Added line #L76 was not covered by tests
args <- rename_aes(args)

idx_false <- vapply(args, isFALSE, FUN.VALUE = logical(1L))
if (isTRUE(any(idx_false))) {
deprecate_warn0("3.3.4", "guides(`<scale>` = 'cannot be `FALSE`. Use \"none\" instead')")
Expand All @@ -84,11 +87,6 @@
return(guides_list(guides = args))
}

# If there are no guides, do nothing
if (length(args) == 0) {
return(NULL)
}

# Raise warning about unnamed guides
nms <- names(args)
if (is.null(nms)) {
Expand Down
6 changes: 5 additions & 1 deletion tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,16 @@ test_that("old S3 guides can be implemented", {

withr::local_environment(my_env)

my_guides <- guides(x = guide_circle())
expect_length(my_guides$guides, 1)
expect_s3_class(my_guides$guides[[1]], "guide")

expect_snapshot_warning(
expect_doppelganger(
"old S3 guide drawing a circle",
ggplot(mtcars, aes(disp, mpg)) +
geom_point() +
guides(x = "circle")
my_guides
)
)
})
Expand Down
Loading