In subdir I have a file krkx.jl which just contains a simple module:
module Krkx
export superfunc
function superfunc(x, y)
x + y - y
end
end
I want to import this module from a notebook in dir. What puzzles me is the following behaviour: When I create a Jupyter notebook using IJulia in dir I can create the following cell:
include(./subdir/krkx.jl")
using .Krkx
This gives me the expected behaviour and I can use my new superfunc in subsequent cells. However, if I try to do this in Pluto I get the following error message: “ArgumentError: Package Krkx not found in current path:”
I’d very much appreciate why including and using my local file is possible in Jupyter but not in Pluto - and whether there is a way to give me this functionality in Pluto.
I can’t tell you exactly why, but including files is not quite as straightforward in Pluto, presumably due to its reactivity. What should work, however, is assigning the include with the module to a variable:
module TESTMOD
export hello
function hello()
"HELLO"
end
end
If I am not mistaken Pluto generates a new workspace everytime you run a cell, and simply bring into the new workspaces everything you didn’t delete from previous workspaces.
The problem with the approach above is that the using would give you an error when loading the notebook and you would have to re-run the cell with some appropriate workspace number afterwards.
In general including files directly in Pluto is not recommended, you can find some more details on the discussion to Pluto issue 115 on GH