Good afternoon! Suppose I want to write a function that calls another, specifying by default certain options in that call, but I also want the user to be able to override those options and also specify any other options available for the called function. I illustrate with a toy example function that does a ListPlot, but with the option Frame->True.The following partly works, in that it sets the Frame option to one that is different from the ListPlot default, and yet can be overridden
Clear[mySpecialPlot]
Options[mySpecialPlot] = {Frame -> True};
mySpecialPlot[data_, opts : OptionsPattern[]] := Module[{},
ListPlot[data, Frame -> OptionValue[Frame]]
]
mySpecialPlot[{1, 2, 3, 4, 5}]
mySpecialPlot[{1, 2, 3, 4, 5}, Frame -> False]
However, what it does not do is allow the user of mySpecialPlot to pass through other ListPlot options. So instead, I tried this:
Clear[mySpecialPlot]
Options[mySpecialPlot] = {Frame -> True};
mySpecialPlot[data_, opts : OptionsPattern[]] := Module[{},
ListPlot[data, FilterRules[{opts}, Options[ListPlot]]]
]
mySpecialPlot[{1, 2, 3, 4, 5}, Background -> GrayLevel[0.95]]
mySpecialPlot[{1, 2, 3, 4, 5}, Frame -> True,
Background -> GrayLevel[0.95]]
This does do the pass-though but it does not respect the Options[] command setting the new default. I have to specify it explicitly
So each code does one of the things I want: how can I combine them?