Skip to content

Improve facet error messages in animint2dir - #285

Open
ANAMASGARD wants to merge 3 commits into
masterfrom
fix-168-facet-error-message
Open

Improve facet error messages in animint2dir#285
ANAMASGARD wants to merge 3 commits into
masterfrom
fix-168-facet-error-message

Conversation

@ANAMASGARD

@ANAMASGARD ANAMASGARD commented Dec 21, 2025

Copy link
Copy Markdown
Contributor

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.

@ANAMASGARD

ANAMASGARD commented Dec 22, 2025

Copy link
Copy Markdown
Contributor Author

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

codecov Bot commented Dec 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.08%. Comparing base (426295c) to head (a4307cd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
+ Coverage   73.03%   73.08%   +0.05%     
==========================================
  Files         164      164              
  Lines        8840     8858      +18     
==========================================
+ Hits         6456     6474      +18     
  Misses       2384     2384              
Flag Coverage Δ
javascript 81.25% <ø> (ø)
r 69.23% <100.00%> (+0.09%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 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

tdhock commented Dec 22, 2025

Copy link
Copy Markdown
Collaborator

No obvious timing issues in HEAD=fix-168-facet-error-message
Comparison Plot

Generated via commit c1877ef

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

Task Duration
R setup and installing dependencies 2 minutes and 12 seconds
Installing different package versions 27 seconds
Running and plotting the test cases 3 minutes and 29 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
Comment thread R/facet-layout.r Outdated
Comment thread R/z_animintHelpers.R Outdated
Comment thread R/facet-layout.r Outdated
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

Also Sir @tdhock atime performance tests / comment job failing actually has nothing to do with this PR :

  • It installs animint2 from an old baseline commit to compare performance before and after my changes
  • The baseline commit it is using is 352f7e1 (version 2025.9.16)

Where it crashes:

It crashes during R CMD INSTALL of that old commit with this error:

Error: geom_dotplot.Rd:125: processing build-stage \Sexpr code failed:
Error: No geom called GeomDotplot.
ERROR: installing Rd objects failed
Error in atime_versions_install(...) :
  '/opt/R/4.6.0/lib/R/bin/R' CMD INSTALL returned error status code 1 

Why does this happen:

  • That old commit's geom_dotplot.Rd has a \Sexpr line that looks up GeomDotplot at build time
  • GeomDotplot was removed from animint2 after that commit
  • So the old doc file now breaks when installed under R 4.6.0
  • The current man/geom_dotplot.Rd on master is already fixed — this is only broken in that old commit

My changes are never even reached — the job dies at install time before running any performance tests.

There is also this warning in the log:

Warning: CRAN version=2025.10.17 but installed version=2026.2.28
fix via install.packages('animint2') 

This is an infrastructure/CI issue, not a code issue. Can you please tell what should I do not it is happening in my other PR's also .

@ANAMASGARD
ANAMASGARD requested a review from tdhock May 26, 2026 17:17
Comment thread R/facet-layout.r Outdated
Comment thread R/facet-layout.r Outdated

@tdhock tdhock left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revise

test_that("facet_wrap formula with missing variable gives clear error", {
viz <- list(
scatter = ggplot() +
facet_wrap(. ~ NonExistentColumn) +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test missing with string notation too?

Suggested change
facet_wrap(. ~ NonExistentColumn) +
facet_wrap("MissingVar") +

)
expect_error(
animint2dir(viz, out.dir = tempfile(), open.browser = FALSE),
"Facet variable not found in data: NonExistentColumn\nAvailable columns: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species\nUse string notation like facet_wrap(\"var\") instead of formula notation facet_wrap(. ~ var)",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error describes two different problems

  • facet variable not found
  • formula notation bad

can you please separate these error messages?

test_that("facet_wrap string notation works", {
viz <- list(
scatter = ggplot() +
facet_wrap("Species") +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work or error?

Suggested change
facet_wrap("Species") +
facet_wrap(~Species) +

ANAMASGARD added a commit that referenced this pull request Jul 25, 2026
Detect facet_wrap(. ~ var) when vars exist and suggest ~var or "var"
notation. Keep missing-variable errors separate without formula advice.
Expand tests per tdhock review on PR #285.
Detect facet_wrap(. ~ var) when vars exist and suggest ~var or "var"
notation. Keep missing-variable errors separate without formula advice.
Expand tests per tdhock review on PR #285.
@ANAMASGARD
ANAMASGARD force-pushed the fix-168-facet-error-message branch from 0fcc9cb to 6c7f082 Compare July 25, 2026 05:47
@ANAMASGARD

Copy link
Copy Markdown
Contributor Author

@tdhock Sorry Sir I accidentally rebased #279 commits were removed. PR now has 1 commit, 2 files — split missing-var vs bad-notation errors, string-missing test, and both facet_wrap(~Species) and facet_wrap("Species") success tests.

Comment thread tests/testthat/test-renderer-facet-error-messages.R Outdated
Comment thread tests/testthat/test-renderer-facet-error-messages.R Outdated
ANAMASGARD and others added 2 commits July 30, 2026 07:11
Use expect_error blocks with animint2dir(viz) and drop explicit
out.dir in success tests per tdhock review on PR #285.
@ANAMASGARD
ANAMASGARD requested a review from tdhock July 30, 2026 08:10
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