Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I was using Needs["PlotLegends"] By chance I removed ShowLegend by Remove[ShowLegend] How do I get back this function without restarting the kernel? Applying Needs["PlotLegends"] again seems not to help.

share|improve this question
    
I edited the title, I hope you don't mind –  ssch Dec 14 '12 at 12:40
2  
Note that reloading a package in such a case is a necessary but often not sufficient measure in such situations. In particular, if there are symbols defined in Mathematica session (in other packages that use that one or otherwise) which refer to the symbol you removed, you have to reload those packages / definitions as well. The problem is made worse by the fact that there are no warnings, neither when you remove the symbol, nor later when you call those functions. Their definitions simply become invalid. And the re-introduction of the symbol into Mathematica session does not help it. –  Leonid Shifrin Dec 14 '12 at 12:56
add comment

1 Answer

up vote 9 down vote accepted

Needs is meant to only load the package if it is not already loaded.

In this case, since you removed one symbol from that context, Needs did not know this, it just looked and saw that the context is there and said, Ok, no need to reload it. It does not look to see that you have removed one symbol from that context.

As a work around, use Get since Get will reload the whole context each time even if it is already loaded before.

Quit[]
Cases[Contexts[], "PlotLegends`"]
(*   {}  *)

Needs["PlotLegends`"]
Cases[Contexts[], "PlotLegends`"]
(*  {"PlotLegends`"}  *)

Cases[Names["PlotLegends`*"], "ShowLegend"]
(* {"ShowLegend"} *)

Remove["PlotLegends`ShowLegend"]
Cases[Names["PlotLegends`*"], "ShowLegend"]
(*  {} *)

Needs["PlotLegends`"]
Cases[Names["PlotLegends`*"], "ShowLegend"]
(*  {}  This shows package was not reloaded, hence symbol still missing*)   

Get["PlotLegends`"]
Cases[Names["PlotLegends`*"], "ShowLegend"]
(* {"ShowLegend"}  OK *)

Hence use Get

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.