Function Repository Resource:

OptionNames

Source Notebook

Get the names of options for a function, possibly filtered according to a pattern

Contributed by: Brett Champion

ResourceFunction["OptionNames"][symbol]

gives the names of options assigned to a symbol.

ResourceFunction["OptionNames"][symbol,patt]

gives the names of options that match the pattern patt.

Details and Options

The pattern patt may be any pattern accepted by StringMatchQ, including patterns using StringExpression and RegularExpression.
ResourceFunction["OptionNames"] takes the following options:
IgnoreCaseFalsematch regardless of case
SpellingCorrectionFalseallow small differences to match

Examples

Basic Examples (2) 

Get the names of options to Plot, without their default values:

In[1]:=
ResourceFunction["OptionNames"][Plot]
Out[1]=

Get the names of options related to PlotRange:

In[2]:=
ResourceFunction["OptionNames"][Plot, "PlotRange*"]
Out[2]=

Scope (2) 

Use StringExpression patterns:

In[3]:=
ResourceFunction["OptionNames"][Plot, "PlotRange" ~~ ___]
Out[3]=

Use regular expressions:

In[4]:=
ResourceFunction["OptionNames"][Plot, RegularExpression["PlotRange.*"]]
Out[4]=

Options (2) 

Find option names even if the case is different:

In[5]:=
ResourceFunction["OptionNames"][Plot, "plotrange*", IgnoreCase -> True]
Out[5]=

Find option names even if the spelling is incorrect:

In[6]:=
ResourceFunction["OptionNames"][Plot, "PlotRagne", SpellingCorrection -> True]
Out[6]=

Applications (2) 

Find the options shared by Plot and NIntegrate:

In[7]:=
Intersection[ResourceFunction["OptionNames"][Plot], ResourceFunction["OptionNames"][NIntegrate]]
Out[7]=

Using Options instead of OptionNames misses Exclusions because it has different default values:

In[8]:=
Intersection[Options[Plot], Options[NIntegrate]]
Out[8]=
In[9]:=
{Options[Plot, Exclusions], Options[NIntegrate, Exclusions]}
Out[9]=

Properties and Relations (1) 

Option names are returned in their original form:

In[10]:=
Options[foo] = {aaaSymbol -> True, "aaaString" -> True, bbb -> False};
In[11]:=
InputForm[ResourceFunction["OptionNames"][foo, "aaa*"]]
Out[11]=

Possible Issues (1) 

Spelling correction only works for literal patterns:

In[12]:=
ResourceFunction["OptionNames"][Plot, "PlotRagne*", SpellingCorrection -> True]
Out[12]=

Publisher

Brett Champion

Version History

  • 1.0.0 – 25 July 2019

License Information