I am attempting to write a package that uses a large number of regression models to estimate parameters from a data set. I want the user to be able to call a single function, FitModel, with a number of options to indicate whether the fit should be linear or nonlinear, and what options should be estimated. To accomplish the option management for FitModel, I wrote a function that uses several nested Which expressions somewhat like a decision tree. The tips of the Which expressions then call a specific model function hidden in the package.
This works when FitModel is called with all default options, which trace the first test in each Which expression. However, any time a Which expression moves to the second test condition, the rest of the decision tree is returned unevaluated.
In theory, I think this should work, but I must be missing something very basic. I would greatly appreciate any suggestions as to how to fix this problem.