OptionValue

OptionValue[name]
gives the value of name in options matched by OptionsPattern.

OptionValue[f,name]
gives the value of name for options associated with the head f.

OptionValue[f,opts,name]
extracts option values from the explicit list of rules opts.

OptionValue[,{name1,name2,}]
extracts several option values.

DetailsDetails

  • OptionValue[name] is equivalent to OptionValue[f,name], where f is the head of the left-hand side of the transformation rule in which OptionValue[name] appears.
  • OptionValue[f,name] and OptionValue[name] will use values from the first OptionsPattern object that appears as an argument of f.
  • In OptionValue[f,opts,name], only the explicit list opts and the defaults derived from f will be considered.
  • In OptionValue[f,opts,name], f can be a symbol, a rule, or a list of symbols and rules specifying default values. Each symbol s in f is equivalent to Options[s]. If the same option name is specified multiple times, the first specification determines the default.
  • OptionValue[f,opts,name,Hold] returns the option value with Hold wrapped around it.
  • OptionValue[Automatic,Automatic,name,Hold] is equivalent to OptionValue[name], except that the option value is returned with Hold wrapped around it.
  • OptionValue ignores contexts when comparing option names and treats the symbol s and the string SymbolName[s] interchangeably.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Define default option values for the function f:

In[1]:=
Click for copyable input

Define f, allowing options to be given:

In[2]:=
Click for copyable input

Use f with an explicit option setting:

In[3]:=
Click for copyable input
Out[3]=

Use f with options taken to have their default values:

In[4]:=
Click for copyable input
Out[4]=
Introduced in 2007
(6.0)