Consider the function
fTest[b_] := Plot[a Sin[x] + b ,{x, -4, 4}],
where a is some real constant.
I can set some standard value for a by Options[fTest] = {a -> 4} and define fTest as:
fTest[b_, OptionsPattern[]] := Plot[OptionValue[a] Sin[x] + b, {x, -4, 4}]
Now fTest should also accept the usual options of Plot.
I tried
Options[fTest] = {a -> 4, Options[Plot]} // Flatten;
fTest[b_, opts : OptionsPattern[]] :=
Plot[OptionValue[a] Sin[x] + b, {x, -4, 4}, opts]
which failed.
A workaround could be achieved via:
fTest[b_, a_: 4, opts : OptionsPattern[]] :=
Plot[a*Sin[x] + b, {x, -4, 4}, opts]
This works, but I would favor a solution where the option is of the form a -> value
So how can I combine the options?
a->4from the options that are fed to Plot. The easiest way is to useEvaluate @ FilterRules[{opts}, Plot]instead ofoptsin your Plot. – Carl Woll Apr 03 '18 at 18:16