Julia's package system and Github are very closely intertwined:
Because of this, it's very useful for everyone using Julia to know a little bit about Git/Github.
An example Github repository for a Julia package is is DifferentialEquations.jl: https://github.com/JuliaDiffEq/DifferentialEquations.jl
The badges on a Github repository show you the current state of the repo. From left to right:
Julia's package manager functions are mirror the Git functions. Julia's package system is similar to R/Python in that a large number of packages are freely available. You search for them in places like Julia Observer, or from the Julia Package Listing. Let's take a look at the Plots.jl package by Tom Breloff. To add a package, use Pkg.add
In [ ]:
using Pkg
Pkg.update() # You may need to update your local packages first
Pkg.add("Plots")
This will install the package to your local system. However, this will only work for registered packages. To add a non-registered package, go to the Github repository to find the clone URL and use Pkg.clone
. For example, to install the ParameterizedFunctions
package, we can use:
In [ ]:
Pkg.clone("https://github.com/JuliaDiffEq/ParameterizedFunctions.jl")
In [5]:
import Plots
Plots.plot(rand(4,4))
Out[5]:
In [6]:
using Plots
plot(rand(4,4))
Out[6]:
What really makes this possible in Julia but not something like Python is that namespace clashes are usually avoided by multiple dispatch. Most packages will define their own types in order to use dispatches, and so when they export the functionality, the methods are only for their own types and thus do not clash with other packages. Therefore it's common in Julia for concise syntax like plot
to be part of packages, all without fear of clashing.
Since Julia is currently under lots of development, you may wish to checkout newer versions. By default, Pkg.add
is the "latest release", meaning the latest tagged version. However, the main version shown in the Github repository is usually the "master" branch. It's good development practice that the latest release is kept "stable", while the "master" branch is kept "working", and development takes place in another branch (many times labelled "dev"). You can choose which branch your local repository takes from. For example, to checkout the master branch, we can use:
In [ ]:
Pkg.checkout("Plots")
This will usually gives us pretty up to date features (if you are using a "unreleased version of Julia" like building from the source of the Julia nightly, you may need to checkout master in order to get some packages working). However, to go to a specific branch we can give the branch as another argument:
In [ ]:
Pkg.checkout("Plots","dev")
This is not advised if you don't know what you're doing (i.e. talk to the developer or read the pull requests (PR)), but this is common if you talk to a developer and they say "yes, I already implemented that. Checkout the dev branch and use plot(...)
).