Skip to content

Improve facet error messages in animint2dir#285

Open
ANAMASGARD wants to merge 6 commits intomasterfrom
fix-168-facet-error-message
Open

Improve facet error messages in animint2dir#285
ANAMASGARD wants to merge 6 commits intomasterfrom
fix-168-facet-error-message

Conversation

@ANAMASGARD
Copy link
Copy Markdown
Contributor

@ANAMASGARD ANAMASGARD commented Dec 21, 2025

FIXES #168

What's broken

viz <- list(
  plot = ggplot() + 
    facet_wrap(. ~ Species) +  # formula notation
    geom_point(aes(x, y), data = iris)
)
animint2dir(viz) 
  • Current error:
    Error: At least one layer must contain all variables used for facetting

Doesn't tell you what's wrong or how to fix it.

  • Workaround that works:
    facet_wrap("Species") # string notation works fine

What I am fixing

  1. Detect when formula notation is used in facets
  2. Give clear error telling user to use string notation instead
  3. Fix happens in animint2dir() - animint2-specific code only

Next commit will add the fix to make tests pass.

Issue #168 - facet_wrap(. ~ var) gives unhelpful error when var is missing.

Added tests that will pass once we improve error messages in animint2dir().
Tests cover facet_wrap and facet_grid with missing variables.

These tests are animint2-specific .
When facet_wrap or facet_grid uses formula notation with a variable
that does not exist in the data, the error now shows:
- Which variable is missing
- What columns are available
- Suggests using string notation instead

Fixes #168
@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

ANAMASGARD commented Dec 22, 2025

Before :-

Error: At least one layer must contain all variables used for facetting

After :-

Error: Facet variable not found in data: MissingVar
Available columns: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species
Use string notation like facet_wrap("var") instead of formula notation facet_wrap(. ~ var) ```

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.12%. Comparing base (543d0d9) to head (bf4c37c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
+ Coverage   73.09%   73.12%   +0.02%     
==========================================
  Files         164      164              
  Lines        8769     8778       +9     
==========================================
+ Hits         6410     6419       +9     
  Misses       2359     2359              
Flag Coverage Δ
javascript 80.78% <ø> (ø)
r 69.61% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tdhock
Copy link
Copy Markdown
Collaborator

tdhock commented Dec 22, 2025

  • HEAD=fix-168-facet-error-message much slower for getCommonChunk improved in #238
    Comparison Plot

Generated via commit bf4c37c

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 4 minutes and 1 seconds
Installing different package versions 1 minutes and 0 seconds
Running and plotting the test cases 2 minutes and 43 seconds

@ANAMASGARD
Copy link
Copy Markdown
Contributor Author

Sir @tdhock The 2 failing tests in JS_coverage are in test-compiler-ghpages.R (GitHub Pages tests), not related to this PR. This is the same race condition issue where parallel CI jobs conflict over the shared test repository.

All facet-related tests pass:

  • R_coverage: 2096+ tests passed
  • CRAN: passed
  • My 3 new facet error message tests pass

The fix is working correctly. Please review and give your feedback Sir .

@ANAMASGARD ANAMASGARD requested a review from tdhock December 22, 2025 10:04
Comment thread tests/testthat/test-renderer-facet-error-messages.R Outdated
Comment thread R/z_animintHelpers.R Outdated
@ANAMASGARD ANAMASGARD requested a review from tdhock March 18, 2026 03:30
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

Successfully merging this pull request may close these issues.

facet_wrap ~var errors but "var" works

2 participants