Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Pass options down from one function into the next when the default option values are different
ResourceFunction["InheritOptions"][f→g] creates a list of options for g from options entered into f, taking account the fact that f might have different default option values. | |
ResourceFunction["InheritOptions"][f→g,opts] uses options opts instead of the defaults. | |
ResourceFunction["InheritOptions"][f→g,assoc] treats an Association as an option specification. |
Create option rules for a function g, assuming that it was called from f and should use those default values where possible:
In[1]:= |
Out[3]= |
Explicit options will override the defaults and only options valid for g will be passed down:
In[4]:= |
Out[4]= |
InheritOptions will work with any option specification after the first argument. A Sequence of rules:
In[5]:= |
Out[5]= |
A list of rules:
In[6]:= |
Out[6]= |
Specifying options as an Association is also supported:
In[7]:= |
Out[7]= |
Normally, FilterRules is used to pass options down to a lower function:
In[8]:= |
In[9]:= |
Out[9]= |
However, if the defaults of f change, this will not actually change the default behavior of f since the default for g still gets used:
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
InheritOptions will always use the default values of the main function:
In[12]:= |
Out[15]= |
In[16]:= |
Out[17]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License