I would like to make a function that can perform checks on its option values, and resets them to legal values if necessary. The option should still be accessible using OptionValue. I am looking for a way to do this without touching the function's default option values. A minimal example might look something like this:
ClearAll[f];
Options[f] = {"Opt1" -> 1};
f[opts:OptionsPattern[]] :=
If[
OptionValue["Opt1"] < 2, Print["Option value is fine."]; OptionValue["Opt1"],
Print["Option value is illegal."]; resetOption["Opt1", -1]; OptionValue["Opt1"]
];
f["Opt1" -> 4]
This should return -1, but leave the default value at 1. Is there a good way to do this?
EDIT: My real-world function is using OptionValue in several places, and I am looking for a clean way to modify options without having to introduce additional variables. Can this be done?