tidyverse / tidyverse/ggplot2

Partial matching when using named vector as faceting variable

Open Beginner friendly
#6,891 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

internals :mag_right:
Dominant language
R
Stars
7k
Forks
2.1k
Avg merge
59m
Merged PRs (30d)
2

Description

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().

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with options(warn = 2, warnPartialMatchAttr = TRUE), then start from the ggplot2:::id and ggplot2:::id_var calls shown in the backtrace. Trace the attr() lookup involved in the named faceting variable and add or update the relevant regression test if one is found. Done means the faceting example runs without a partial-match warning under those options.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.