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.
As an example, suppose that in a Mathematica session you try to find the mean of a list of numbers without first loading the appropriate package, for instance:
Mean[{3,4,5}] Out[1] = Mean[{3,4,5}]Here you won't receive an error message, but Mathematica also won't do
what you wanted; rather, it will return 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 preempted it. When you load the package,
you'll 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. To make the statistical function available, use the
following command:
The following statistical function will result:
Mean[{3,4,5}] Out[5] = 4In the current version of Mathematica, it doesn't matter whether you
first load a package and then Remove, or whether you do
the reverse.
For more 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.
Last modified on May 02, 2011.







