I found sometimes, I need both OptionValue to get a customized default value and FilterRules in a function.
Below is an illustration of the problem
Options[myPlot] = {cc -> 10};
myPlot[f_, opts : OptionsPattern[]] :=
Module[{},
Plot[f[x] OptionValue[cc], {x, 1, 2},
Evaluate[FilterRules[{opts}, Options[Plot]]], PlotRange -> All]
]
If I run myPlot[Sin, ImageSize -> 600], though the result is fine. However, it will warns me
OptionValue::nodef: Unknown option ImageSize for myPlot.
Trace shows the problems is when executing OptionValue[myPlot, {ImageSize -> 600}, cc] internally. I can't figure out a way to get rid of this warning message instead of using Quiet. So I am asking here if I am using OptionValue the wrong way?
myPlot[f_, opts : OptionsPattern[{myPlot, Plot}]] := (* stuff *). – J. M.'s missing motivation May 11 '17 at 01:27Options[myPlot] = Join[Options[Plot], {cc -> 10}]so that I see all possible options listed when I useOptions[myPlot]. – Carl Woll May 11 '17 at 02:01Plotoption for examplePlotRange -> {0, 10}. Then you can only put them inJoin[{PlotRange -> {0, 10}}, Options[Plot], {cc -> 10}]right beforeOptions[Plot]. However, in J.M. solution, we can put it insidePlot, but have to be sure it is afterEvaluate[FilterRules[{opts}, Options[Plot]]]– matheorem May 11 '17 at 06:20