test_iia() had a scoping conflict when sourced along with other package files.
Error: "object of type 'closure' is not subsettable" or "object 'formula_obj' not found"
R's formula evaluation mechanism in nnet::multinom() was looking for formula parameter names in the wrong environment when all package files were sourced together. This is a classic R formula scoping issue.
Used do.call() to explicitly construct function calls:
# Instead of:
full_model <- nnet::multinom(formula_obj, data_obj, trace = FALSE)
# Use:
full_model <- do.call(nnet::multinom, list(formula_obj, data_obj, trace = FALSE))This ensures proper environment handling during formula evaluation.
force()on parameters - no effect- Dotted variable names (
.formula,.data) - "object not found" errors - Renamed locals (
fml,dat) - same "object not found" - Explicit argument names in multinom() calls - no effect
- Using standard
formula/datanames withmatch.call()- still failed - Different parameter names (
model_formula,dataset) - still failed
- Parameter names:
formula_objanddata_obj(avoids base R conflicts) - Function calls:
do.call(nnet::multinom, list(...))(proper environment handling) - Result: ✅ ALL 15 TESTS PASS
Tests Passed: 15
Tests Failed: 0
✓✓✓ ALL TESTS PASSED! ✓✓✓
New features validated:
✓ test_iia() - Hausman-McFadden IIA test
✓ quick_decision() - Rule-of-thumb recommendations
✓ publication_table() - Camera-ready tables (LaTeX/HTML/markdown)
✓ commuter_choice - Real dataset example
✓ Benchmark data warnings - Honesty labels