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
Components:
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
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:
Pkg.clone("https://github.com/JuliaDiffEq/ParameterizedFunctions.jl")
To use a package, you have to import the package. The import
statement will import the package without exporting the functions to the namespace. (Note that the first time a package is run, it will precompile a lot of the functionality.) For example:
import Plots
Plots.plot(rand(4,4))
To instead export the functions (of the developers choosing) to the namespace, we can use the using
statement. Since Plots.jl exports the plot
command, we can then use it without reference to the package that it came from:
using Plots
plot(rand(4,4))
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:
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:
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(...)
).