For the moderators please have patience. I did look through other previously answered posts similar to this but none worked and of course I made several adjustments with my own code and nothing worked. I even tried ArgumentsOptions
and CheckArguments
but the docs are very poorly written. It's difficult to determine if they go in the definitions or if an end-user should wrap his functions in them.
Below is the standard vanilla method shown in the docs for using FilterRules
. They use Plot
I use Button
.
Options[fn1] = {"background" -> Automatic, "color" -> Black,
"appearance" -> Automatic, , "label" -> "Echo Chamber",
"size" -> {90, 30}};
fn1[opts : OptionsPattern[]] := With[{
bg = OptionValue["background"],
col = OptionValue["color"],
app = OptionValue["appearance"],
lab = OptionValue["label"],
siz = OptionValue["size"]
},
action[] :=
Echo["an \"echo chamber\" is one who often repeats unoriginal \
ideas."];
Button[lab, action[], ImageSize -> siz, BaseStyle -> {col},
Appearance -> app, Background -> bg,
FilterRules[{opts}, Options[Button]]]
];
(* generates 3: OptionValue: Unknown option Evaluator for fn1 *)
(* generates 2: OptionValue: Null is not a valid *)
(* but does render a working button *)
fn1[Evaluator -> Automatic]
(* generates 2: OptionValue: Null is not a valid *)
(* but does render a working button *)
fn1[]
Then I tried a slight variation and that failed too.
Options[fn2] = {"background" -> Automatic, "color" -> Black,
"appearance" -> Automatic, , "label" -> "Echo Chamber",
"size" -> {90, 30}};
fn2[opts : OptionsPattern[]] := With[{
ops = FilterRules[{opts}, Options[Button]],
bg = OptionValue["background"],
col = OptionValue["color"],
app = OptionValue["appearance"],
lab = OptionValue["label"],
siz = OptionValue["size"]
},
action[] :=
Echo["an \"echo chamber\" is one who often repeats unoriginal \
ideas."];
Button[lab, action[], ImageSize -> siz, BaseStyle -> {col},
Appearance -> app, Background -> bg,
If[Length[ops] == 0, Sequence @@ ops, ops]]
];
(* generates 3: OptionValue: Unknown option Evaluator for fn2 *)
(* generates 2: OptionValue: Null is not a valid *)
(* but does render a working button *)
fn2[Evaluator -> Automatic]
(* generates 2: OptionValue: Null is not a valid *)
(* but does render a working button *)
fn2[]
What am I doing wrong?