Import already existing JL file in Pluto?

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

3 Likes

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.

1 Like

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.

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 ?

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

https://github.com/fonsp/Pluto.jl/issues/132

I added something just now

2 Likes

Literate.jl 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…

1 Like

You should write one!

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!

1 Like

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

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

6 Likes

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

And feel free to share your results in that issue!

1 Like

Any news on this?

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?

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

Drag&Drop support is coming:

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.

2 Likes

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?

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?

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 ?

2 Likes

@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:

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! :slight_smile:

Happy to having been useful to you !

2 Likes

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

include("../sample_download.jl")
2 Likes