# Clean workspace, plot pane, and console on re-run in Julia

**URL:** https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475
**Category:** Juno
**Tags:** first-steps
**Created:** [May 14, 2020, 3:36pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475 "2020-05-14T15:36:02Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [May 14, 2020, 3:36pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/1 "2020-05-14T15:36:02Z")

</div>

I am used to starting all my Matlab scripts with `clear all; close all; clc` to ensure I am not looking at any old data or plots. I found Julia’s `clearconsole()` to be equivalent to Matlab’s `clc`, but don’t have working solutions for the other two Matlab commands yet. I mostly work in the Juno IDE and run scripts with the Play (“Run All”) button.

I understand that the Revise.jl package is supposed to help refresh the workspace now that `workspace()` is deprecated, but it doesn’t work for this simple test case. If I define `x` once and then comment that line out, it will continue to print each time I run without error.

```julia
using Revise
clearconsole()
#x=1
println(x)

```

I know I can hit “Stop” then “Play” to reset the workspace. However, that still doesn’t close old plots, and the [time to first plot problem](https://discourse.julialang.org/t/roadmap-for-a-faster-time-to-first-plot/22956) makes this option undesirable.

I found the “Forget All Plots” button in Juno’s plot pane, but I would like to have that functionality as a line in my script instead. Currently, it takes me three clicks to run a script again after I edit it (four if I include “Stop”).

1. “Forget All Plots”
2. Somewhere in the editor to put focus back on my current file.
3. “Run All”

I would ideally like to re-run in a fresh environment with one click or keystroke, but any tips on a better Juno workflow would be appreciated.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [May 14, 2020, 4:50pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/2 "2020-05-14T16:50:52Z")

</div>

For a “clear all” equivalent, you can use a module. If your script looks like this:

```julia
module MyModule
x = 3
end #module

```

Then, each time you re-run the script, you will see the message “WARNING: replacing module MyModule”, and any functions/variables that you created in there will be lost.  
At the REPL, you can access the variables as e.g. `MyModule.x`.

If you want to compare the results before/after some change to the code, then re-name the module in your script and run it again. Now you have access to results of both runs, and can compute things like `MyModule.x - MyNewModule.x`.

Another option is to write functions instead of scripts.

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [May 14, 2020, 5:10pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/3 "2020-05-14T17:10:19Z")

</div>

This is a cool option that I will definitely use for testing script changes, but wrapping code in a module or function makes the Juno Workspace pretty useless for debugging at a glance. On the other hand, I know I am supposed to avoid global variables in Julia, so maybe I will need to come up with another method for rapid debugging. What is typically done to glance at all the variables inside a function and check that they have the correct type and value?

---

<div class="post-metadata">

### Author: ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)
#### Post date: [May 14, 2020, 5:35pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/4 "2020-05-14T17:35:02Z")

</div>

I try to wrap all my work in functions so that I am mostly dealing with local variables rather than lingering globals (unless I am doing very quick prototyping in the REPL). This also has the added benefit of faster performance but ofcourse, when prototyping or quick data analysis, optimization/speed isn’t a big concern.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 14, 2020, 5:55pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/5 "2020-05-14T17:55:19Z")

</div>

The workspace works for all globals and globals in modules are still, well, global.

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [May 14, 2020, 6:20pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/6 "2020-05-14T18:20:56Z")

</div>

![JunoScreenshot1](https://global.discourse-cdn.com/julialang/original/3X/4/7/475e48ada84804a0a8bf865dcc628ad9537d219c.png)

The workspace doesn’t seem to be showing my variables when I run this script.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [May 14, 2020, 6:31pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/7 "2020-05-14T18:31:57Z")

</div>

Click on the little box in the top-right corner and select “MyModule”.  
 ![Screen Shot 2020-05-14 at 20.37.23](https://global.discourse-cdn.com/julialang/original/3X/2/1/21f838e3f2d94301d37338f51e507240fbbb9a3a.png)

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [May 14, 2020, 6:42pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/8 "2020-05-14T18:42:11Z")

</div>

Ooo, got it! That makes modules much more useful. 😁

I guess the last point to address in my question then is if there is a better method to manage plots?

(I will probably post a separate question about best methods to debug functions.)

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [May 14, 2020, 7:37pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/9 "2020-05-14T19:37:15Z")

</div>

We could add a function to Juno.jl that allows you to clear the plot pane programatically. Please open an issue at [Sign in to GitHub · GitHub](https://github.com/JunoLab/Juno.jl/issues/new).

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [May 16, 2020, 1:19pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/10 "2020-05-16T13:19:10Z")

</div>

I created a new Juno issue on [Github](https://github.com/JunoLab/Juno.jl/issues/581) about a function to clear the plot pane. Thank you for the suggestions!

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [June 19, 2020, 12:23pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/11 "2020-06-19T12:23:02Z")

</div>

Does Visual Studio Code have `clearconsole()` or `clearplotpane()` equivalent commands now that the IDE of choice seems to be VS Code rather than Atom?

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [June 19, 2020, 12:53pm UTC](https://discourse.julialang.org/t/clean-workspace-plot-pane-and-console-on-re-run-in-julia/39475/12 "2020-06-19T12:53:41Z")

</div>

No. Feel free to open a feature request [here](https://github.com/julia-vscode/julia-vscode/issues/new).
