Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to undo `using` in Julia?

Tags:

module

julia

Suppose in the Julia console I do

using Gadfly

And then realise I actually want to use a different plot command

using Winston

It seems that plot() will still use the Gadfly version. Is there any way to stop using Gadfly?

using !Gadfly
!using Gadfly
unuse Gadfly

Something like that?

like image 521
Timmmm Avatar asked Mar 27 '16 15:03

Timmmm


2 Answers

As mentioned in the link by @Jubobs, there is currently not a way to selectively stop using a package, or selectively remove a definition from the REPL (similar to Matlab's clear command if you are familiar with it). So the short answer is no.

However, you can reference functions from specific modules by using Gadfly.plot(), or Winston.plot(). This doesn't provide you a solution to your problem if you have already written the code, but it is still an option for future work.

There is the workspace() command but that will remove everything from the Main module and will import a fresh Julia environment. You will lose all the functions and variables you have defined... so use it wisely

As @Matt B pointed out, you don't actually lose your functions and variables. They are moved to a module called LastMain. So if I have a function defined called myfunc(), and I call workspace(), then attempting to call myfunc() at the REPL will result in an UndefVarError. However, you will still be able access this function by calling LastMain.myfunc(). This is true of anything that was defined in the REPL before your call to workspace().

like image 178
hyperdelia Avatar answered Sep 16 '22 19:09

hyperdelia


As others have pointed out, you cannot unload a package in Julia. The only way to do that would be to restart the Julia repl. However, if you want to use a specific function from a package, you can us Winston.plot() or Gadfly.plot(). Thus will ensure, you're using the right function from the desired namespace.

like image 24
niczky12 Avatar answered Sep 16 '22 19:09

niczky12