Skip to content

Commit 3d1102c

Browse files
authored
Restore old guides in guides() (#6167)
* Early exit earlier * fix `is.guide()` -> `inherits()` * explicitly test `guides()` adds old S3 guides properly
1 parent 50b7d30 commit 3d1102c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

R/guides-.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ NULL
6868
#' }
6969
guides <- function(...) {
7070
args <- list2(...)
71-
if (length(args) > 0) {
72-
if (is.list(args[[1]]) && !is.guide(args[[1]])) args <- args[[1]]
73-
args <- rename_aes(args)
71+
# If there are no guides do nothing
72+
if (length(args) == 0) {
73+
return(NULL)
7474
}
7575

76+
if (is.list(args[[1]]) && !inherits(args[[1]], "guide")) args <- args[[1]]
77+
args <- rename_aes(args)
78+
7679
idx_false <- vapply(args, isFALSE, FUN.VALUE = logical(1L))
7780
if (isTRUE(any(idx_false))) {
7881
deprecate_warn0("3.3.4", "guides(`<scale>` = 'cannot be `FALSE`. Use \"none\" instead')")
@@ -84,11 +87,6 @@ guides <- function(...) {
8487
return(guides_list(guides = args))
8588
}
8689

87-
# If there are no guides, do nothing
88-
if (length(args) == 0) {
89-
return(NULL)
90-
}
91-
9290
# Raise warning about unnamed guides
9391
nms <- names(args)
9492
if (is.null(nms)) {

tests/testthat/test-guides.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,16 @@ test_that("old S3 guides can be implemented", {
577577

578578
withr::local_environment(my_env)
579579

580+
my_guides <- guides(x = guide_circle())
581+
expect_length(my_guides$guides, 1)
582+
expect_s3_class(my_guides$guides[[1]], "guide")
583+
580584
expect_snapshot_warning(
581585
expect_doppelganger(
582586
"old S3 guide drawing a circle",
583587
ggplot(mtcars, aes(disp, mpg)) +
584588
geom_point() +
585-
guides(x = "circle")
589+
my_guides
586590
)
587591
)
588592
})

0 commit comments

Comments
 (0)