Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

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:

Remove["Mean"]

The following statistical function will result:

Mean[{3,4,5}] Out[5] = 4

In 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.

This is document afto in domain all.
Last modified on May 02, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.