Pluto vs. IJulia: Including a Local Module

Hello everyone,

say, I have a small directory tree like this:

+dir
|
+--subdir

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.

Kind regards,

Thomas

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:

Krkx=include(“./subdir/krkx.jl”)
Krkx.superfunc(1,2)

Apart from the solution from @Jakob, if you really want to have access to the exported functions it seems you can do it in this hacky way:

where TESTMOD.jl is only:

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