Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
Options[myPlot] = Options[Plot];
myPlot[args___] := ...

When defining a "wrapper" function like the above, I'd like it to inherit the System` function's options. Should I use Options[myPlot] = Options[Plot] or Options[myPlot] := Options[Plot]?

share|improve this question

1 Answer 1

up vote 11 down vote accepted

I use the first style you gave:

Options[tListPlot]=Join[
    Options[ListPlot],
    Options[tLegend],
    {
        Rule[ShowLegend,False]
    }
];

The function is then defined as

tListPlot[data_,options:OptionsPattern[]]:=...

I don't see any reason to use SetDelayed (:=) in this context. EDIT As Brett Champion mentions in the comments, the default options for

System`Plot

will change if you use SetOptions on Plot. Hence, if you want your custom plot to always have the same options as Plot, use :=. I would prefer to specifically change the options for my Plot separately, so I would still use simply Set (=).

You might also want to check out this instructive question on Options in custom functions: Functions with Options

share|improve this answer
5  
The default options of Plot will change if you use SetOptions. Using SetDelayed will pick up that change, unless SetOptions has also been applied to myPlot. –  Brett Champion Apr 22 '12 at 2:57
    
+1 Thanks @BrettChampion, I didn't even think of that. I updated the answer to reflect that possibility. –  tkott Apr 22 '12 at 13:38
1  
I'd also like to point out that FilterRules can be used to strip out any additional options that are not present in the wrapped function. –  rcollyer Apr 23 '12 at 3:44
    
+1 Enlightened badge. :-) –  Mr.Wizard Apr 11 '13 at 15:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.