User Tools

Site Tools


Julia Cookbook

About This Cookbook

  • The target audience for this cookbook are new and intermediate Julia users, with programming experience, especially those with an interests in the social sciences; and early application programmers with existing experience in other computer programming languages (especially, R, perl, and/or python).
  • This cookbook is not well-suited to learning programming
  • This cookbook is not well-suited for experienced julia programmers and developers, or those who want to read a book to become one.

The exposition method are minimalistic examples, which should speak for themselves. The reader should immediately understand the functionality by looking at the (working) example. Additional long text explanations are (sometimes necessary) shortcomings in “example exposition.”

About Julia

Julia is a next-generation programming language with many innovations. From my perspective, the most noteworthy general aspects about Julia are:

  • Julia arrays (vectors and matrices) are first-class design features, as are int and float vectors and matrices, making Julia a great scientific language.
  • Julia is strongly typed, making it both easier to find bugs earlier and easier to write efficient programs.
  • Julia relies greatly on function overloading, where the same function name can be assigned to work with different types.
  • Julia is compiled, with requisite compilation overhead. (Think of Julia more as C++, not as perl or R.) It is slow for short programs (compared to python and R), but it is (often blazingly) fast for long programs.

I am recommending Julia because:

  • Julia code is cleaner and more logical than python or perl code, where (float) matrices are subsequent grafts. It is cleaner than R, which has never managed to decide whether it wanted to be primarily an interactive environment or a programming language. R's weak typing means bugs often manifest themselves very late.
  • Julia is less bogged down by its own history than R, Python, or perl. The developers seem to get along and often help users (incl. early users like myself). The julia system has, as of 2018, not yet calcified to the point where even good and simple changes cause endless controversies. Every language must calcify sooner or later, but Julia will do so with the experiences of 2020, not with those of 1990.

In my mind, Julia makes for a worse interactive environment than R (due to R's sloppy language and instant interpreted response speed), and a better programming environment than R (due to Julia's more careful and sane syntax and faster program run speed).

About JuliaComputing and JuliaPro

Julia is an amazing open-source next-gen scientific computer language, designed by some amazing people (Jeff Bezanson, Alan Edelman, Stefan Karpinski, Viral B. Shah, and others). It has enthusiastic supporters that have answered many of my questions while I learned julia (and while I wrote this cookbook). My own contribution for this cookbook was keeping track of and organizing the interesting tidbits while I was learning julia myself. The Perl Cookbook was my primary inspiration for this cookbook. This book is what made perl usable for me at the time. (Thank you, Tom and Nathan!) I hope this julia cookbook will help make julia usable for others.

JuliaComputing employs the core developers for Julia. To help finance Julia's development, please support them by purchasing their products:

  1. JuliaPro is Julia with a set of curated and more stable packages, an IDE, and enterprise support.

I have not yet used the following:

  1. JuliaBox is a web-based interface to a working and curated Julia, sold for a modest per month subscription price.
  2. JuliaRun is for large distributed cluster operations.
  3. JuliaDB is for operations on large disk-based data sets.

Julia Core Language

Julia consists of a core computer language and packages. Packages can add essential functionality (e.g., Missing values or DataFrame as dataset storage), programming tools (e.g., BenchmarkTools or Parallel Programming support), and/or applications (e.g., statistical analysis or plotting). Julia is not a lightweight language, with few principal features to remember, like C or lisp. It is a beast with many heads and appendages, tremendously powerful, but also easy to get lost in—similar to R (with CRAN), python (with PyPI), and perl (with CPAN) in this respect.

  1. Introduction
    1. Installation and Packages also REPL (Interactive) and Batch Use.
    2. Inquiring about object types and structures, methods and functions, naming conventions, etc.

  2. Command Flow
  3. Scalars
  4. Strings
    1. Basics: concatenations, substrings, conversions, padding, capitalization, characterizations, parsing, escaping, etc.
    2. Regular Expressions: finding and matching complex patterns.

  5. Arrays and Tuples
  6. Associative Arrays (Key-Value)
    1. Dictionaries: (=maps=hashes), could be viewed as run-time structs.
    2. Structures: could be viewed as compile-time dictionaries.

  7. Functions
  8. DataFrames
    1. Introduction: building and accessing dataframes
    2. Missing and NaN: in the context of data frames
    3. Complex Operations: sorts, joins, by-group operations, wide-narrow conversions
    4. Input/Output: csv files, binary IO, databases (SQL), and R data. FIXME when csv-IO stabilizes

Julia Tools, Packages, and Applications

The next set of topics are really extended tools, packages, and applications rather than language topics.

  1. Programming (see also Functions above).
    1. More Tools: Debugging, Profiling, Benchmarking, Testing, Writing Packages.
    2. Parallel Processing: See also Functions above. With (shared) read-only and read-write memory.
    3. Translation Notes R, Matlab, python, perl. FIXME

  2. Files and Operating System
    1. File Input/Output: incl. running (and capturing) external programs.
    2. Operating and File System: command-line args, OS detection, globbing, recursive directory traversals, etc.

  3. Mathematical Search Algorithms
    1. Other Topics in Minimizations (Integers, Constrained, Multiple Objectives, etc.)

  4. Statistics
    1. Univariate Statistics: tabulating, classifying, summary statistics, quantiles,
    2. Clustering, Classifications, etc. FIXME Tileman?
    3. Sample Analysis Sessions

  5. Plotting: Introduction FIXME Tileman
    1. With PyPlot
    2. With Gadfly — avoid in 0.6.2
    3. With Plotly — examples in doc no longer working

  6. Finance Support FIXME Tileman?
    1. Prominent Data Sources (Edgar, Fred, French, Intrinio, Etc.)
    2. Equities (Fama-Macbeth, Event Studies, Pfio Optimization, Factor-Analysis, Fama-French 92, etc.)
    3. Derivatives (Fixed Income, Options).



If you want to help, please email me where I got things wrong.

This cookbook was written by Ivo Welch, with some early help from Pranav Bhat. Tileman Conring is coming on board, too.

Many of the solutions are based on help from folks at JuliaComputing and the julia discourse forum. Special thanks to Tamas_Papp, Nosferican, Mohamed82008, Steveng, StefanK, and others.
This cookbook is taking intellectual credit only for the organization of the examples and exposition. Julia and its packages were written by others, and it is these authors that deserve the intellectual credit. (And ultimately, it is they who designed and thus could explain originally how to use the features.)

This wiki uses DokuWiki, with the github-markdown syntax (and not the regular Dokuwiki syntax).


FIXME For the cookbook itself, write meta code: [1] copy code popup button; [2] LaTeX mapper.


Enter your comment. Wiki syntax is allowed:
start.txt · Last modified: 2018/03/17 11:38 (external edit)