# Import already existing JL file in Pluto?

**URL:** https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484
**Category:** Pluto
**Tags:** pluto, parsing
**Created:** [August 7, 2020, 8:59am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484 "2020-08-07T08:59:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [August 7, 2020, 8:59am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/1 "2020-08-07T08:59:41Z")

</div>

Dear All, Pluto expert users and/or developers, I wonder is there would be an easy way to import and existing Julia (.jl) file into Pluto, without having to manually create new cells and do cut and paste (with begin end insertions at some times…) ?

I know I am lazy, but may be it could be usefull, eg for converting from plan JL and/or IJulia notebooks? (as of now, I am wondering which technology is most suitable for which kind of tasks)

thanks for comments,  
JDAD

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [August 7, 2020, 9:04am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/2 "2020-08-07T09:04:48Z")

</div>

In julia everywhere, `include("thefiletoload.jl")` should load the `.jl` file into the current context. I don’t know if you are needing more than that.

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [August 7, 2020, 9:51am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/3 "2020-08-07T09:51:18Z")

</div>

This includes results of the file, but does not enable to edit interactively as Pluto’s goal. I would like to have the text of the file inside cell(s) of Pluto, so to continue to develop, or modify parameters …

J.

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [August 8, 2020, 8:02am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/4 "2020-08-08T08:02:26Z")

</div>

By the way, the work is equally tedious when covertiing plain julia/REPL file to IJUlia notebook, except that you can start by having only on giant cell containing everyting, then split it accordingly to desires.

With Pluto there is the additional chore to wrap each new cell with begin/end, so to be sure that the system work. An automatic way of doing this (or, an automatic cleaner that would remove begin-end (or let-end without vars) when there is no error generated for the cell) could be useful. But I understand the case for it would be very narrow , so I would guess would not fit with Pluto development (@fonsp) process ?

---

<div class="post-metadata">

### Author: ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)
#### Post date: [August 12, 2020, 9:58am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/5 "2020-08-12T09:58:36Z")

</div>

Hey! I wrote down my thoughts on integrating it into Pluto here:

[https://github.com/fonsp/Pluto.jl/issues/132](https://github.com/fonsp/Pluto.jl/issues/132)

I added something just now

---

<div class="post-metadata">

### Author: ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)
#### Post date: [August 12, 2020, 10:30am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/6 "2020-08-12T10:30:04Z")

</div>

> [@jdad](#):
>
> By the way, the work is equally tedious when covertiing plain julia/REPL file to IJUlia notebook, except that you can start by having only on giant cell containing everyting, then split it accordingly to desires.

[Literate.jl](https://fredrikekre.github.io/Literate.jl/v2/) can interoperate between Julia source, Markdown (something you’d use for Documenter.jl) and Jupyter notebook. Now, if it only had an interface for Pluto…

---

<div class="post-metadata">

### Author: ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)
#### Post date: [August 12, 2020, 1:20pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/7 "2020-08-12T13:20:10Z")

</div>

You should write one!

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [August 12, 2020, 2:38pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/8 "2020-08-12T14:38:11Z")

</div>

Dear @anon37204545, thanks for the reference, it can be useful !

Dear @fonsp, thanks for the references and the support! Yes, may be I will try to write one, using your examples… in such case I will report on it!

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [August 13, 2020, 9:13am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/9 "2020-08-13T09:13:12Z")

</div>

I have written a small script that seems to do the work. Comments welcome ! @fonsp

[https://github.com/jdadavid/Jl2pluto.jl](https://github.com/jdadavid/Jl2pluto.jl)

---

<div class="post-metadata">

### Author: ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)
#### Post date: [August 13, 2020, 5:54pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/10 "2020-08-13T17:54:08Z")

</div>

Great! Did you try the two-argument Meta.parse? That might make the script a lot simpler:  
[https://github.com/fonsp/Pluto.jl/issues/132#issuecomment-672776959](https://github.com/fonsp/Pluto.jl/issues/132#issuecomment-672776959)

And feel free to share your results in that issue!

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [December 19, 2020, 11:21pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/11 "2020-12-19T23:21:51Z")

</div>

Any news on this?

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [December 20, 2020, 4:51am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/12 "2020-12-20T04:51:31Z")

</div>

As my utility did work for me, I marked it as Solution, and then did no further work.  
I just now additionally commented on the GitHub thread mentioned above (should have done that at that time, sorry).

What would you like to see as further news?

---

<div class="post-metadata">

### Author: ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)
#### Post date: [December 20, 2020, 5:04pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/13 "2020-12-20T17:04:16Z")

</div>

Thanks for the answer. I was expecting a way to import at the browser interface itself. Meanwhile, your solution is very nit.

---

<div class="post-metadata">

### Author: ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)
#### Post date: [December 20, 2020, 5:27pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/14 "2020-12-20T17:27:43Z")

</div>

Drag&Drop support is coming:

[https://github.com/fonsp/Pluto.jl/pull/707](https://github.com/fonsp/Pluto.jl/pull/707)

With this functionality, you can just drag your jl file into a Pluto notebook and its content is pasted to a Pluto cell.  
For optimal usage into Pluto, you probably need to do some manual modifications like splitting into multiple cells.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 3, 2021, 9:01am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/15 "2021-01-03T09:01:51Z")

</div>

Does a script exist that does the reverse operation? I.e., that sanitizes a Pluto script (stripping out all the Pluto internals) so that the resulting \*.jl file displays nicely in VS Code?

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [January 3, 2021, 1:32pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/16 "2021-01-03T13:32:18Z")

</div>

I do not know of such a script, but it should be easy to prototype one, peeling out the # annotations. Just an interrogation to think about, if using the bind facilities of PlutoUI, then should probably keep it?

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [January 4, 2021, 5:02pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/17 "2021-01-04T17:02:08Z")

</div>

I have uploaded such a prototype script to my previous repository

`https://github.com/jdadavid/Jl2pluto.jl`

script is named `Plutojl2jl.jl`

Hopefully it answers your asking @rafael.guerra ?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 4, 2021, 7:58pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/18 "2021-01-04T19:58:38Z")

</div>

@jdad, thanks for your nice prototype script which was written in 100% Julia (with no packages used)! As a Windows user trying to stay away as much as possible from the DOS terminal, preferred running the script from VS Code by bypassing the command-line input arguments’ logic and jumping straight to around row#82 in the script, defining:

```julia
inplace = false
enableoverwrite = true
keepblank = false # this was missing in prototype
inputfile = "C:/Users/jrafa/ex1_Pluto.jl"
outputfile = inputfile * "_out.jl"

```

The result was a Pluto-clean \*.jl file.  
Thank you so much! 🙂

---

<div class="post-metadata">

### Author: ![jdad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jdad/32/4739_2.png) [@jdad](https://discourse.julialang.org/u/jdad)
#### Post date: [January 4, 2021, 9:38pm UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/19 "2021-01-04T21:38:46Z")

</div>

Happy to having been useful to you !

---

<div class="post-metadata">

### Author: ![bicepjai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicepjai/32/18158_2.png) [@bicepjai](https://discourse.julialang.org/u/bicepjai)
#### Post date: [February 18, 2021, 7:23am UTC](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484/20 "2021-02-18T07:23:00Z")

</div>

In pluto notebook, can we reload a file that has already been included ?

```julia
include("../sample_download.jl")

```

[Next page](https://discourse.julialang.org/t/import-already-existing-jl-file-in-pluto/44484.md?page=2)
