NBInclude is a package for the Julia language which allows you to include and execute IJulia (Julia-language Jupyter) notebook files just as you would include an ordinary Julia file. That is, analogous to doing
include("myfile.jl") in Julia to execute
myfile.jl, you can do
using NBInclude nbinclude("myfile.ipynb")
to execute all of the code cells in the IJulia notebook
myfile.ipynb. Similar to
include, the value of the last evaluated expression in the last evaluated code cell is returned.
The goal of this package is to make notebook files just as easy to incorporate into Julia programs as ordinary Julia (
.jl) files, giving you the advantages of a notebook (integrated code, formatted text, equations, graphics, and other results) while retaining the modularity and re-usability of
Key features of NBInclude are:
Min input cell
myfile.ipynbnotebook. Un-numbered cells (e.g. unevaluated cells) are given a number
N-th nonempty cell in the notebook. You can use
nbinclude("myfile.ipynb", renumber=true)to automatically renumber the cells in sequence (as if you had selected Run All from the Jupyter Cell menu), without altering the file.
/path/to/myfile.ipynb:In[N]for input cell
nbincludeworks fine with parallel Julia processes, even for worker processes (from Julia's
addprocs) that may not have filesystem access. (Do
import NBInclude; @everywhere using NBIncludeto use
nbincludeon all processes.)
?are interpreted as shell commands or help requests, respectively. Such cells are ignored by
regexkeywords can be used to include a subset of notebook cells to those for which
counter ∈ countersand the cell text matches
regex. For example,
nbinclude("notebook.ipynb"; counters=1:10, regex=r"#\s*EXECUTE")would include cells 1 to 10 from
notebook.ipynbthat contain comments like
anshookcan be used to run a passed function on the return value of all the cells.
To install it, simply do
Pkg.add("NBInclude") as usual for Julia packages.
26 days ago