Skip to content

Conversation

@ayushsingh9720
Copy link

Summary

This Pull Request addresses issue #6512 by making the error message in melt.data.table more informative when a user provides column names in measure.vars that do not exist in the dataset.

Changes

  • R/fmelt.R: Added a pre-check for character measure.vars. It uses setdiff() to identify exactly which variables are missing from the data and reports them specifically.
  • inst/tests/tests.Rraw: Added a new test case (ID 2154.1) to verify that the specific error message is triggered correctly.
  • src/fmelt.c: Cleaned up the C logic to ensure it remains a robust fallback, while the primary informative error is handled in R.

Impact

Instead of a generic:
Error: One or more values in 'measure.vars' is invalid.

Users will now see:
Error: One or more values in 'measure.vars' is invalid; please fix by removing [z1]

This change improves the developer experience by pinpointing the exact typo or missing column in the function call.

Closes #6512

@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (851467f) to head (5bb9ff4).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7549   +/-   ##
=======================================
  Coverage   98.96%   98.96%           
=======================================
  Files          87       87           
  Lines       16734    16741    +7     
=======================================
+ Hits        16560    16567    +7     
  Misses        174      174           

☔ 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.

Copy link
Member

@ben-schwen ben-schwen left a comment

Choose a reason for hiding this comment

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

Good start. Case for list(measure.vars) is definitely missing.

@@ -1,3 +1,4 @@
if (getRversion() >= "2.15.1") utils::globalVariables(c("n_read"))
Copy link
Member

Choose a reason for hiding this comment

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

please explain this change!

melt(DT, id.vars=patterns("[in]"), measure.vars=patterns("^f_", "^d_"), value.factor=TRUE)
# same as above, but provide list of columns directly by column names or indices
melt(DT, id.vars=1:2, measure.vars=list(3:4, c("d_1", "d_2")), value.factor=TRUE)
try(melt(DT, id.vars=1:2, measure.vars=list(3:4, c("d_1", "d_2")), value.factor=TRUE))
Copy link
Member

Choose a reason for hiding this comment

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

why try?

@ayushsingh9720 ayushsingh9720 deleted the gsoc-fix-beginner-task branch January 7, 2026 14:33
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.

melt error message for bad measure.vars could be more informative/specific

2 participants