diff --git a/R/guides-.R b/R/guides-.R index debb99237e..0e7ca26882 100644 --- a/R/guides-.R +++ b/R/guides-.R @@ -68,11 +68,14 @@ NULL #' } 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]] + args <- rename_aes(args) + idx_false <- vapply(args, isFALSE, FUN.VALUE = logical(1L)) if (isTRUE(any(idx_false))) { deprecate_warn0("3.3.4", "guides(`` = 'cannot be `FALSE`. Use \"none\" instead')") @@ -84,11 +87,6 @@ guides <- function(...) { 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)) { diff --git a/tests/testthat/test-guides.R b/tests/testthat/test-guides.R index 31ce6c8b98..5718e4f2ad 100644 --- a/tests/testthat/test-guides.R +++ b/tests/testthat/test-guides.R @@ -577,12 +577,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 ) ) })