Resources

A glorified calculator

Variables

Variables are assigned with =.

Notice how the vector was still printed even though we were just assigning a value? We can prevent this behvaior by appending a function call with ;.

We can assign variables to unicode representations!

Arrays & Tuples

Groups of items are stored in arrays, tuples, and dictionaries. Arrays are created with [ and tuples with (.

The difference between and array and a tuple is that tuples are immutable (they can't be changed once created).

z, is the equivalent of c(1, 2, 3, 4) in R. With the , we create a vector. If we omit it we create a matrix.

Arrays are indexed starting at 1.

Shell mode

Shell mode is entered by first type ;. We can then directly interact with the terminal. No more multiple windows!

Pkg mode

Pkg mode can be entered by typing ] in the REPL. Package mode is where you add/manage Julia packages as well as project environments. Julia comes with the ability to work in projects with distinct package environments. This is allows us to share a project with others and not worry about package versions, etc. To activate a project:

To add a package we use the add command followed by the name of the project:

What if we wanted to share a project with someone?

Notice that 2 files we're created when I added a package after calling activate , Manifest.toml and Project.toml. These .toml files contain the information about the state of the project.

If I were to share this project with a collaborator, they would run:

;activate .
;instantiate

Documentation

Similarly to R, we can access Julia documentation with ?. This tells Julia to enter Help mode. Let's look at the documentation for the mean function.

We receive a message that the "Binding mean does not exist." This is because the mean function is part of the Statistics.jl package. To load the package we use using.

I didn't have to add the Statistics package because it's part of the base ecosystem for Julia. However, unlike R, this package is automatically loaded when starting a Julia session.

Functions

From the Julia wiki: "A function is a collected group of instructions that can return one or more values, possibly based on the input arguments..." Just like in R, a function maps an input to an output.

Functions are defined with the function keyword.

Notice that the function scope is closed with the end keyword. This is in contrast to R which use {} or Python which uses tabs (ew...). There is also function definition shorthand we can use.

Anonymous functions can be defined using the -> syntax.

Methods

Functions can have multiple methods where the methods performs a specific job based on the types of the function arguments.

What happens if we pass in a number instead of a string?

This is multiple dispatch! Based on the types of the arguments passed to the method Julia decides how to properly execute the function. It's called multiple dispatch because the dispatching can occur on multiple argument types. Contrast this with the S3 system in R where the method can only be decided on using the class of the first argument. We can see all the different methods associated with a function with methods.

Iteration

We can create a for loop using the for keyword.

Julia also makes use of list comprehension.

There's also a map.

Another option is called broadcasting. We can broadcast any function by appending the function name with .. If the function is an operator, then we add . to the beginning of the operator.

Types

Interoperability with other languages

We can use R within Julia with the RCall package. This is also possible with Python, MATLAB, Mathmatica.