Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 1.77 KB

File metadata and controls

50 lines (39 loc) · 1.77 KB

test_iia() Scoping Issue - RESOLVED

Problem

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"

Root Cause

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.

Solution ✅

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.

Attempted Fixes (Did Not Work)

  1. force() on parameters - no effect
  2. Dotted variable names (.formula, .data) - "object not found" errors
  3. Renamed locals (fml, dat) - same "object not found"
  4. Explicit argument names in multinom() calls - no effect
  5. Using standard formula/data names with match.call() - still failed
  6. Different parameter names (model_formula, dataset) - still failed

Final Implementation

  • Parameter names: formula_obj and data_obj (avoids base R conflicts)
  • Function calls: do.call(nnet::multinom, list(...)) (proper environment handling)
  • Result: ✅ ALL 15 TESTS PASS

Test Results

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

Status: RESOLVED ✅