Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

##General

Some time ago, I wrote a package specifically to address this issue. It is named PackageManipulations and described in this postthis post. The package can be imported as

Import["http://www.mathprogramming-intro.org/download/packages/PackageManipulations.m"]

It has an accompanying notebook with detailed explanations of how to use it, but I will give a brief summary here.

##PackageManipulations package

The main functions in the package are PackageClear, PackageClearComplete, PackageReload, and PackageRemove. They do what they say.

###Reloading the package

Use

PackageReload[your-package-context], 

to reload your package. Note that PackageReload calls PackageClearComplete (described below), and thus clears previous definitions that symbols in your package's context and its sub-contexts may have had (but does not remove the symbols). Thus, this should be the most frequently used tool in the context of package testing.

You may call

PackageReload[your-package-context, KillShadowing -> True]

if you want to resolve some existing shadowing conflict in favor of the symbol in the package being reloaded - the other symbol will then be Removed.

###Clearing the symbols in the package without removing them.

If you just want to clear all the names of all symbols in the context of your package, but keep the package' s context and symbol names in the system, you can call

PackageClear[your-package-context]

To clear (but not remove) the context together with all sub - contexts, use

PackageClearComplete[your-package-context]

###Removing the package from the system

To remove the context and all its sub-contexts, use PackageClearComplete with the RemovePackage -> True option :

PackageClearComplete[your-package-context, RemovePackage -> True]

A somewhat lower-level function to remove all package symbols and the entire package from the system is PackageRemove:

PackageRemove[your-package-context]

It Removes all the symbols in the specified context, and also removes the context from $ContextPath and $Packages, if it is there. It does not, however, deal with sub-contexts, so the proper way to completely remove the package from the system is to call PackageClearComplete with the RemovePackage -> True option, as mentioned above.

Note that removal is not an innocent operation, since all definitions outside the package being removed, which referenced some of the symbols in the package, will be permanently invalidated, until those definitions themselves are reloaded. Clearing definitions but keeping the symbols does not lead to this issue.

##Notes

The linked notebook contains more detailed explanations and examples.

The package is rather old, and may not work in some cases. If something does not work, let me know, and I will make sure to fix the issue.

##General

Some time ago, I wrote a package specifically to address this issue. It is named PackageManipulations and described in this post. The package can be imported as

Import["http://www.mathprogramming-intro.org/download/packages/PackageManipulations.m"]

It has an accompanying notebook with detailed explanations of how to use it, but I will give a brief summary here.

##PackageManipulations package

The main functions in the package are PackageClear, PackageClearComplete, PackageReload, and PackageRemove. They do what they say.

###Reloading the package

Use

PackageReload[your-package-context], 

to reload your package. Note that PackageReload calls PackageClearComplete (described below), and thus clears previous definitions that symbols in your package's context and its sub-contexts may have had (but does not remove the symbols). Thus, this should be the most frequently used tool in the context of package testing.

You may call

PackageReload[your-package-context, KillShadowing -> True]

if you want to resolve some existing shadowing conflict in favor of the symbol in the package being reloaded - the other symbol will then be Removed.

###Clearing the symbols in the package without removing them.

If you just want to clear all the names of all symbols in the context of your package, but keep the package' s context and symbol names in the system, you can call

PackageClear[your-package-context]

To clear (but not remove) the context together with all sub - contexts, use

PackageClearComplete[your-package-context]

###Removing the package from the system

To remove the context and all its sub-contexts, use PackageClearComplete with the RemovePackage -> True option :

PackageClearComplete[your-package-context, RemovePackage -> True]

A somewhat lower-level function to remove all package symbols and the entire package from the system is PackageRemove:

PackageRemove[your-package-context]

It Removes all the symbols in the specified context, and also removes the context from $ContextPath and $Packages, if it is there. It does not, however, deal with sub-contexts, so the proper way to completely remove the package from the system is to call PackageClearComplete with the RemovePackage -> True option, as mentioned above.

Note that removal is not an innocent operation, since all definitions outside the package being removed, which referenced some of the symbols in the package, will be permanently invalidated, until those definitions themselves are reloaded. Clearing definitions but keeping the symbols does not lead to this issue.

##Notes

The linked notebook contains more detailed explanations and examples.

The package is rather old, and may not work in some cases. If something does not work, let me know, and I will make sure to fix the issue.

##General

Some time ago, I wrote a package specifically to address this issue. It is named PackageManipulations and described in this post. The package can be imported as

Import["http://www.mathprogramming-intro.org/download/packages/PackageManipulations.m"]

It has an accompanying notebook with detailed explanations of how to use it, but I will give a brief summary here.

##PackageManipulations package

The main functions in the package are PackageClear, PackageClearComplete, PackageReload, and PackageRemove. They do what they say.

###Reloading the package

Use

PackageReload[your-package-context], 

to reload your package. Note that PackageReload calls PackageClearComplete (described below), and thus clears previous definitions that symbols in your package's context and its sub-contexts may have had (but does not remove the symbols). Thus, this should be the most frequently used tool in the context of package testing.

You may call

PackageReload[your-package-context, KillShadowing -> True]

if you want to resolve some existing shadowing conflict in favor of the symbol in the package being reloaded - the other symbol will then be Removed.

###Clearing the symbols in the package without removing them.

If you just want to clear all the names of all symbols in the context of your package, but keep the package' s context and symbol names in the system, you can call

PackageClear[your-package-context]

To clear (but not remove) the context together with all sub - contexts, use

PackageClearComplete[your-package-context]

###Removing the package from the system

To remove the context and all its sub-contexts, use PackageClearComplete with the RemovePackage -> True option :

PackageClearComplete[your-package-context, RemovePackage -> True]

A somewhat lower-level function to remove all package symbols and the entire package from the system is PackageRemove:

PackageRemove[your-package-context]

It Removes all the symbols in the specified context, and also removes the context from $ContextPath and $Packages, if it is there. It does not, however, deal with sub-contexts, so the proper way to completely remove the package from the system is to call PackageClearComplete with the RemovePackage -> True option, as mentioned above.

Note that removal is not an innocent operation, since all definitions outside the package being removed, which referenced some of the symbols in the package, will be permanently invalidated, until those definitions themselves are reloaded. Clearing definitions but keeping the symbols does not lead to this issue.

##Notes

The linked notebook contains more detailed explanations and examples.

The package is rather old, and may not work in some cases. If something does not work, let me know, and I will make sure to fix the issue.

Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424

##General

Some time ago, I wrote a package specifically to address this issue. It is named PackageManipulations and described in this post. The package can be imported as

Import["http://www.mathprogramming-intro.org/download/packages/PackageManipulations.m"]

It has an accompanying notebook with detailed explanations of how to use it, but I will give a brief summary here.

##PackageManipulations package

The main functions in the package are PackageClear, PackageClearComplete, PackageReload, and PackageRemove. They do what they say.

###Reloading the package

Use

PackageReload[your-package-context], 

to reload your package. Note that PackageReload calls PackageClearComplete (described below), and thus clears previous definitions that symbols in your package's context and its sub-contexts may have had (but does not remove the symbols). Thus, this should be the most frequently used tool in the context of package testing.

You may call

PackageReload[your-package-context, KillShadowing -> True]

if you want to resolve some existing shadowing conflict in favor of the symbol in the package being reloaded - the other symbol will then be Removed.

###Clearing the symbols in the package without removing them.

If you just want to clear all the names of all symbols in the context of your package, but keep the package' s context and symbol names in the system, you can call

PackageClear[your-package-context]

To clear (but not remove) the context together with all sub - contexts, use

PackageClearComplete[your-package-context]

###Removing the package from the system

To remove the context and all its sub-contexts, use PackageClearComplete with the RemovePackage -> True option :

PackageClearComplete[your-package-context, RemovePackage -> True]

A somewhat lower-level function to remove all package symbols and the entire package from the system is PackageRemove:

PackageRemove[your-package-context]

It Removes all the symbols in the specified context, and also removes the context from $ContextPath and $Packages, if it is there. It does not, however, deal with sub-contexts, so the proper way to completely remove the package from the system is to call PackageClearComplete with the RemovePackage -> True option, as mentioned above.

Note that removal is not an innocent operation, since all definitions outside the package being removed, which referenced some of the symbols in the package, will be permanently invalidated, until those definitions themselves are reloaded. Clearing definitions but keeping the symbols does not lead to this issue.

##Notes

The linked notebook contains more detailed explanations and examples.

The package is rather old, and may not work in some cases. If something does not work, let me know, and I will make sure to fix the issue.