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.
-
$\begingroup$ I edited the title, I hope you don't mind $\endgroup$– sschCommented Dec 14, 2012 at 12:40
-
2$\begingroup$ 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. $\endgroup$– Leonid ShifrinCommented Dec 14, 2012 at 12:56
1 Answer
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