GithubHelp home page GithubHelp logo

fagan2888 / nbinclude.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from juliainterop/nbinclude.jl

0.0 0.0 0.0 38 KB

import code from IJulia Jupyter notebooks into Julia programs

License: Other

Julia 46.31% Jupyter Notebook 53.69%

nbinclude.jl's Introduction

NBInclude

Build Status Build status

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 .jl files.

Note: Scoping rules have changed between Julia 0.6 and Julia 1.0. Running a notebook as @nbinclude("foo.ipynb"; softscope=true) will load notebooks as they work for interactive use in the IJulia kernel ("soft" global scoping, or 0.6-style). That flag's default value, false, will load notebooks with the "hard" scoping rule of Julia 1.0 (e.g. in include); see the SoftGlobalScope package for more details.

Key features of NBInclude are:

  • The path of the notebook is relative to the path of the current file (if any), and nested inclusions can use paths relative to the notebook, just as for include.
  • In a module, included notebooks work fine with precompilation in Julia 0.4 (and re-compilation is automatically triggered if the notebook changes).
  • Code is associated with accurate line numbers (e.g. for backtraces when exceptions are thrown), in the form of myfile.ipynb:In[N]:M for line M in input cell N of the myfile.ipynb notebook. Un-numbered cells (e.g. unevaluated cells) are given a number +N for the 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.
  • The Julia @__FILE__ macro returns /path/to/myfile.ipynb:In[N] for input cell N.
  • In IJulia, cells beginning with ; or ? are interpreted as shell commands or help requests, respectively. Such cells are ignored by @nbinclude.
  • counters and regex keywords can be used to include a subset of notebook cells to those for which counter โˆˆ counters and 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.ipynb that contain comments like # EXECUTE.
  • A keyword anshook can be used to run a passed function on the return value of all the cells.
  • No Python or Jupyter dependency.
  • The softscope flag mentioned above.

To install it, simply do Pkg.add("NBInclude") as usual for Julia packages.

Contact

NBInclude was written by Steven G. Johnson and is free/open-source software under the MIT/Expat license. Please file bug reports and feature requests at the NBInclude github page.

nbinclude.jl's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.