In Mathematica, if I forget to load a package before I first use one of its functions, how can I recover?
If you forget to load a package in Mathematica before you first use one of its functions, use the following command to recover:
Remove["function"]Replace function with the name of the function. You can
then load the package successfully.
Suppose that in a Mathematica session you try to find the mean of a list of numbers without first loading the appropriate package, for example:
Mean[{3,4,5}] Out[1] = Mean[{3,4,5}]There isn't an error message, but Mathematica didn't do what you
wanted; rather, it returned your input unchanged. When you realize
your error and load the descriptive statistics package, the
Mean function will still be unavailable, since your
earlier use of the term has pre-empted it. When you load the package,
you receive the following warning:
"<<Statistics`DescriptiveStatistics`
Mean::shdw: Warning: Symbol Mean appears in multiple contexts
{Statistics`DescriptiveStatistics`, Global`}; definitions in context Statistics`DescriptiveStatistics` may shadow or be shadowed by other definitions."
This means that the earlier use of Mean established its
existence in the Global context, which takes precedence over the one
you want. However, you can use the following command to make the
statistical function available:
The following statistical function will result:
Mean[{3,4,5}] Out[5] = 4In the current version of Mathematica, it does not matter whether you
load first and then Remove, but it is is more intuitive
to Remove first and then load the correct package.
For more information about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.
Also see:
- Where can I get help with Mathematica?
- In Mathematica, how can I save and print a graphic?
- In Mathematica, why is the program only making new lines when I press Return?
Last modified on November 17, 2008.






