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

guides() breaks old guides if the first argument is an old guide #6306

Open
eliocamp opened this issue Jan 24, 2025 · 1 comment
Open

guides() breaks old guides if the first argument is an old guide #6306

eliocamp opened this issue Jan 24, 2025 · 1 comment

Comments

@eliocamp
Copy link
Contributor

The old guide system used lists. This trips up a check in guides(), which throws this spurious warning:

library(ggplot2)

old_guide <- metR:::guide_colourstrip()
is.list(old_guide)
#> [1] TRUE

new_guide <- guide_colorbar()
is.list(new_guide)
#> [1] FALSE

mtcars |> 
    ggplot(aes(gear, carb)) +
    geom_point() +
    guides(fill = old_guide)
#> Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
#> of ggplot2 3.3.4.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

The problem is here:

ggplot2/R/guides-.R

Lines 76 to 83 in 97edd62

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(`<scale>` = 'cannot be `FALSE`. Use \"none\" instead')")
args[idx_false] <- "none"
}

Line 76 seems to be there to support a guides(list(fill = ..., colour = ...)) syntax. But when using the old guide system, the logic makes args point to the first guide. Then line 79 iterates over the elements of the guide and if one of them is FALSE then it converts it to "none" and throws the warning.

@eliocamp eliocamp changed the title guides() throw espurious warning when using old guides. guides() breaks breaks old guides. Jan 24, 2025
@eliocamp eliocamp changed the title guides() breaks breaks old guides. guides() breaks breaks old guides if the first argument is an old guide Jan 24, 2025
@eliocamp eliocamp changed the title guides() breaks breaks old guides if the first argument is an old guide guides() breaks old guides if the first argument is an old guide Jan 24, 2025
@teunbrand
Copy link
Collaborator

Thanks for the report Elio! I think this might be a duplicate of #6165, for which we merged a fix 3 days ago. Does updating the development version of ggplot2 help at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants