Skip to content

Partial matching when using named vector as faceting variable #6891

Description

@fkohrt

Via larmarange/ggstats#126 I stumbled upon the fact that using a named vector as faceting variable emits an error for options(warn = 2, warnPartialMatchAttr = TRUE):

df <- list2DF(list(
  x = 1:2,
  y = 1:2,
  facet = setNames(
    factor(c("a", "b")),
    c("one", "two")
  )
))

ggplot2::ggplot(df, ggplot2::aes(x, y)) +
  ggplot2::geom_point() +
  ggplot2::facet_grid(rows = ggplot2::vars(facet))
Error in `attr()`:
! (converted from warning) partial argument match of 'n' to 'names'
Backtrace:
     ▆
  1. ├─base (local) `<fn>`(x)
  2. ├─ggplot2 (local) `print.ggplot2::ggplot`(x)
  3. │ ├─ggplot2::ggplot_build(x)
  4. │ └─ggplot2 (local) `ggplot_build.ggplot2::ggplot`(x)
  5. │   └─layout$setup(data, plot@data, plot@plot_env)
  6. │     └─ggplot2 (local) setup(..., self = self)
  7. │       └─self$facet$compute_layout(data, self$facet_params)
  8. │         └─ggplot2 (local) compute_layout(..., self = self)
  9. │           └─ggplot2:::id(base, drop = TRUE)
 10. │             └─ggplot2:::id_var(.variables[[1]], drop = drop)
 11. └─base::warning(cond)
 12.   └─base::withRestarts(...)
 13.     └─base (local) withOneRestart(expr, restarts[[1L]])
 14.       └─base (local) doWithOneRestart(return(expr), restart)

It may be necessary to pass exact = TRUE to attr().

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