Skip to content

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

Closed
@eliocamp

Description

@eliocamp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions