This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Utilities  /


The function FilterOptions is used to select valid options when passing options from one function to another.

A utility function for passing options.

As an application of FilterOptions, consider writing a new function PlotIntegrate that calls the functions Plot and NIntegrate and plots the numerical integral of a function. Although the function PlotIntegrate does not use options directly, it passes options along to Plot and NIntegrate. Options that are valid for NIntegrate, however, are not valid for Plot, and options that are valid for Plot are not valid for NIntegrate. The function FilterOptions is used to select a valid set of options for each function.

  • This loads the package.
  • In[1]:= << Utilities`FilterOptions`

  • Here is a simple program that uses the FilterOptions function. Valid options are selected using FilterOptions before passing the option sequence to Plot or NIntegrate.
  • In[2]:= PlotIntegrate[f_, {x_, a_, b_}, opts___] :=
    optPlot = FilterOptions[Plot, opts],
    optNInt = FilterOptions[NIntegrate,
    NIntegrate[f, {x, a, t}, optNInt],
    {t, a, b}, optPlot] ]

  • In this example, the Frame->True and GridLines->Automatic options are passed to Plot but not to NIntegrate. An error would occur if these options were passed to both functions.
  • In[3]:= PlotIntegrate[Sin[x], {x, 0, 3},
    Frame -> True, GridLines -> Automatic]