This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / Add-ons & Links / Standard Packages / Utilities /

Utilities`FilterOptions`

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 Integrate and plots the integral of a function. Although the function PlotIntegrate does not use options directly, it passes options along to Plot and Integrate. Options that are valid for Integrate, however, are not valid for Plot, and options that are valid for Plot are not valid for Integrate. 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 Integrate.

In[2]:= PlotIntegrate[f_, {x_, a_, b_}, opts___] :=
With[{
optPlot = FilterOptions[Plot, opts],
optInt = FilterOptions[Integrate, opts]},
Plot[
Integrate[f, {x, a, t}, optInt],
{t, a, b}, optPlot] ]

In this example, the Frame -> True and GridLines -> Automatic options are passed to Plot but not to Integrate. An error would occur if these options were passed to both functions.

In[3]:= PlotIntegrate[Sin[x], {x, 0, 3},
Frame -> True, GridLines -> Automatic]

Out[3]=