If I have a custom function with optional values, how can I find all the options used for a particular call?
If I write:
ClearAll[f];
Options[f]={opt1->42,opt2->""};
f[x_,options:OptionsPattern[]]:=Module[{},
Row[{"x = ",x,", options: ",options}]
];
f[4711,opt2->"this is opt2"]
(* ==> x = 4711, options: opt2->this is opt2 *)
... I only get the options that were actually used by the caller.
To get all options, I have only found the following solution:
ClearAll[f];
Options[f]={opt1->42,opt2->""};
f[x_,options:OptionsPattern[]]:=Module[{allOptions},
allOptions=First[#]->OptionValue[First[#]]&/@Options[f];
Row[{"x = ",x,", All options: ",allOptions,", Caller options: ",options}]
];
f[4711,opt2->"this is opt2"]
(* ==> x = 4711, All options: {opt1->42,opt2->this is opt2}, Caller options: opt2->this is opt2 *)
This works, but it is not very elegant. Is there a better way?