3.5 Julia Standard Library

Julia has a rich standard library that is available with every Julia installation. Contrary to everything that we have seen so far, e.g. types, data structures and filesystem; you must load standard library modules into your environment to use a particular module or function.

This is done via using or import. In this book, we will load code via using:

  1. using ModuleName

After doing this, you can access all functions and types inside ModuleName.

3.5.1 Dates

Knowing how to handle dates and timestamps is important in data science. As we said in Why Julia? (Section 2) section, Python’s pandas uses its own datetime type to handle dates. The same is true in the R tidyverse’s lubridate package, which also defines its own datetime type to handle dates. In Julia packages don’t need to write their own dates logic, because Julia has a dates module in its standard library called Dates.

To begin, let’s load the Dates module:

  1. using Dates

3.5.1.1 Date and DateTime Types

The Dates standard library module has two types for working with dates:

  1. Date: representing time in days and
  2. DateTime: representing time in millisecond precision.

We can construct Date and DateTime with the default constructor either by specifying an integer to represent year, month, day, hours and so on:

  1. Date(1987) # year
  1. 1987-01-01
  1. Date(1987, 9) # year, month
  1. 1987-09-01
  1. Date(1987, 9, 13) # year, month, day
  1. 1987-09-13
  1. DateTime(1987, 9, 13, 21) # year, month, day, hour
  1. 1987-09-13T21:00:00
  1. DateTime(1987, 9, 13, 21, 21) # year, month, day, hour, minute
  1. 1987-09-13T21:21:00

For the curious, September 13th 1987, 21:21 is the official time of birth of the first author, Jose.

We can also pass Period types to the default constructor. Period types are the human-equivalent representation of time for the computer. Julia’s Dates have the following Period abstract subtypes:

  1. subtypes(Period)
  1. DatePeriod
  1. TimePeriod

which divide into the following concrete types, and they are pretty much self-explanatory:

  1. subtypes(DatePeriod)
  1. Day
  1. Month
  1. Quarter
  1. Week
  1. Year
  1. subtypes(TimePeriod)
  1. Hour
  1. Microsecond
  1. Millisecond
  1. Minute
  1. Nanosecond
  1. Second

So, we could alternatively construct Jose’s official time of birth as:

  1. DateTime(Year(1987), Month(9), Day(13), Hour(21), Minute(21))
  1. 1987-09-13T21:21:00

3.5.1.2 Parsing Dates

Most of the time, we won’t be constructing Date or DateTime instances from scratch. Actually, we will probably be parsing strings as Date or DateTime types.

The Date and DateTime constructors can be fed a string and a format string. For example, the string "19870913" representing September 13th 1987 can be parsed with:

  1. Date("19870913", "yyyymmdd")
  1. 1987-09-13

Notice that the second argument is a string representation of the format. We have the first four digits representing year y, followed by two digits for month m and finally two digits for day d.

It also works for timestamps with DateTime:

  1. DateTime("1987-09-13T21:21:00", "yyyy-mm-ddTHH:MM:SS")
  1. 1987-09-13T21:21:00

You can find more on how to specify different date formats in the Julia Dates’ documentation. Don’t worry if you have to revisit it all the time, we ourselves do that too when working with dates and timestamps.

According to Julia Dates’ documentation, using the Date(date_string, format_string) method is fine if it’s only called a few times. If there are many similarly formatted date strings to parse, however, it is much more efficient to first create a DateFormat type, and then pass it instead of a raw format string. Then, our previous example becomes:

  1. format = DateFormat("yyyymmdd")
  2. Date("19870913", format)
  1. 1987-09-13

Alternatively, without loss of performance, you can use the string literal prefix dateformat"...":

  1. Date("19870913", dateformat"yyyymmdd")
  1. 1987-09-13

3.5.1.3 Extracting Date Information

It is easy to extract desired information from Date and DateTime objects. First, let’s create an instance of a very special date:

  1. my_birthday = Date("1987-09-13")
  1. 1987-09-13

We can extract anything we want from my_birthday:

  1. year(my_birthday)
  1. 1987
  1. month(my_birthday)
  1. 9
  1. day(my_birthday)
  1. 13

Julia’s Dates module also has compound functions that return a tuple of values:

  1. yearmonth(my_birthday)
  1. (1987, 9)
  1. monthday(my_birthday)
  1. (9, 13)
  1. yearmonthday(my_birthday)
  1. (1987, 9, 13)

We can also see the day of the week and other handy stuff:

  1. dayofweek(my_birthday)
  1. 7
  1. dayname(my_birthday)
  1. Sunday
  1. dayofweekofmonth(my_birthday)
  1. 2

Yep, Jose was born on the second Sunday of September.

NOTE: Here’s a handy tip to just recover weekdays from Dates instances. Just use a filter on dayofweek(your_date) <= 5. For business day you can checkout the BusinessDays.jl package.

3.5.1.4 Date Operations

We can perform operations in Dates instances. For example, we can add days to a Date or DateTime instance. Notice that Julia’s Dates will automatically perform the adjustments necessary for leap years, and for months with 30 or 31 days (this is known as calendrical arithmetic).

  1. my_birthday + Day(90)
  1. 1987-12-12

We can add as many as we like:

  1. my_birthday + Day(90) + Month(2) + Year(1)
  1. 1989-02-11

In case you’re ever wondering: “What can I do with dates again? What is available?” then you can use methodswith to check it out. We show only the first 20 results here:

  1. first(methodswith(Date), 20)
  1. [1] +(dt::Date, t::Time) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:19
  2. [2] +(dt::Date, y::Year) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:27
  3. [3] +(dt::Date, z::Month) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:54
  4. [4] +(x::Date, y::Quarter) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:73
  5. [5] +(x::Date, y::Week) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:77
  6. [6] +(x::Date, y::Day) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:79
  7. [7] +(t::Time, dt::Date) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:20
  8. [8] -(dt::Date, y::Year) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:35
  9. [9] -(dt::Date, z::Month) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:66
  10. [10] -(x::Date, y::Quarter) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:74
  11. [11] -(x::Date, y::Week) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:78
  12. [12] -(x::Date, y::Day) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/arithmetic.jl:80
  13. [13] convert(::Type{DateTime}, dt::Date) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/conversions.jl:30
  14. [14] convert(::Type{Day}, dt::Date) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/conversions.jl:37
  15. [15] floor(dt::Date, p::Year) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/rounding.jl:45
  16. [16] floor(dt::Date, p::Month) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/rounding.jl:51
  17. [17] floor(dt::Date, p::Quarter) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/rounding.jl:61
  18. [18] floor(dt::Date, p::Week) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/rounding.jl:66
  19. [19] floor(dt::Date, p::Day) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/rounding.jl:73
  20. [20] print(io::IO, dt::Date) in Dates at /opt/hostedtoolcache/julia/1.8.4/x64/share/julia/stdlib/v1.8/Dates/src/io.jl:722

From this, we can conclude that we can also use the plus + and minus - operator. Let’s see how old Jose is, in days:

  1. today() - my_birthday
  1. 12886 days

The default duration of Date types is a Day instance. For the DateTime, the default duration is Millisecond instance:

  1. DateTime(today()) - DateTime(my_birthday)
  1. 1113350400000 milliseconds

3.5.1.5 Date Intervals

One nice thing about Dates module is that we can also easily construct date and time intervals. Julia is clever enough to not have to define the whole interval types and operations that we covered in Section 3.3.6. It just extends the functions and operations defined for range to Date’s types. This is known as multiple dispatch and we already covered this in Why Julia? (Section 2).

For example, suppose that you want to create a Day interval. This is easy done with the colon : operator:

  1. Date("2021-01-01"):Day(1):Date("2021-01-07")
  1. 2021-01-01
  1. 2021-01-02
  1. 2021-01-03
  1. 2021-01-04
  1. 2021-01-05
  1. 2021-01-06
  1. 2021-01-07

There is nothing special in using Day(1) as the interval, we can use whatever Period type as interval. For example, using 3 days as the interval:

  1. Date("2021-01-01"):Day(3):Date("2021-01-07")
  1. 2021-01-01
  1. 2021-01-04
  1. 2021-01-07

Or even months:

  1. Date("2021-01-01"):Month(1):Date("2021-03-01")
  1. 2021-01-01
  1. 2021-02-01
  1. 2021-03-01

Note that the type of this interval is a StepRange with the Date and concrete Period type we used as interval inside the colon : operator:

  1. date_interval = Date("2021-01-01"):Month(1):Date("2021-03-01")
  2. typeof(date_interval)
  1. StepRange{Date, Month}

We can convert this to a vector with the collect function:

  1. collected_date_interval = collect(date_interval)
  1. 2021-01-01
  1. 2021-02-01
  1. 2021-03-01

And have all the array functionalities available, like, for example, indexing:

  1. collected_date_interval[end]
  1. 2021-03-01

We can also broadcast date operations to our vector of Dates:

  1. collected_date_interval .+ Day(10)
  1. 2021-01-11
  1. 2021-02-11
  1. 2021-03-11

Similarly, these examples work for DateTime types too.

3.5.2 Random Numbers

Another important module in Julia’s standard library is the Random module. This module deals with random number generation. Random is a rich library and, if you’re interested, you should consult Julia’s Random documentation. We will cover only three functions: rand, randn and seed!.

To begin, we first load the Random module. Since we know exactly what we want to load, we can just as well do that explicitly:

  1. using Random: seed!

We have two main functions that generate random numbers:

  • rand: samples a random element of a data structure or type.
  • randn: samples a random number from a standard normal distribution (mean 0 and standard deviation 1).

3.5.2.1 rand

By default, if you call rand without arguments it will return a Float64 in the interval \([0, 1)\), which means between 0 inclusive to 1 exclusive:

  1. rand()
  1. 0.9037965496029162

You can modify rand arguments in several ways. For example, suppose you want more than 1 random number:

  1. rand(3)
  1. [0.05657119977569813, 0.8125154052666181, 0.4909845628484597]

Or, you want a different interval:

  1. rand(1.0:10.0)
  1. 5.0

You can also specify a different step size inside the interval and a different type. Here we are using numbers without the dot . so Julia will interpret them as Int64 and not as Float64:

  1. rand(2:2:20)
  1. 6

You can also mix and match arguments:

  1. rand(2:2:20, 3)
  1. [14, 6, 4]

It also supports a collection of elements as a tuple:

  1. rand((42, "Julia", 3.14))
  1. 42

And also arrays:

  1. rand([1, 2, 3])
  1. 3

Dicts:

  1. rand(Dict(:one => 1, :two => 2))
  1. :one => 1

For all the rand arguments options, you can specify the desired random number dimensions in a tuple. If you do this, the returned type will be an array. For example, here’s a 2x2 matrix of Float64 numbers between 1.0 and 3.0:

  1. rand(1.0:3.0, (2, 2))
  1. 2×2 Matrix{Float64}:
  2. 1.0 2.0
  3. 2.0 2.0

3.5.2.2 randn

randn follows the same general principle from rand but now it only returns numbers generated from the standard normal distribution. The standard normal distribution is the normal distribution with mean 0 and standard deviation 1. The default type is Float64 and it only allows for subtypes of AbstractFloat or Complex:

  1. randn()
  1. 0.8020065125890842

We can only specify the size:

  1. randn((2, 2))
  1. 2×2 Matrix{Float64}:
  2. -0.609552 -0.16923
  3. -1.74446 -1.10169

3.5.2.3 seed!

To finish off the Random overview, let’s talk about reproducibility. Often, we want to make something replicable. Meaning that, we want the random number generator to generate the same random sequence of numbers. We can do so with the seed! function:

  1. seed!(123)
  2. rand(3)
  1. [0.521213795535383, 0.5868067574533484, 0.8908786980927811]
  1. seed!(123)
  2. rand(3)
  1. [0.521213795535383, 0.5868067574533484, 0.8908786980927811]

In some cases, calling seed! at the beginning of your script is not good enough. To avoid rand or randn to depend on a global variable, we can instead define an instance of a seed! and pass it as a first argument of either rand or randn.

  1. my_seed = seed!(123)
  1. Random.TaskLocalRNG()
  1. rand(my_seed, 3)
  1. [0.521213795535383, 0.5868067574533484, 0.8908786980927811]
  1. rand(my_seed, 3)
  1. [0.19090669902576285, 0.5256623915420473, 0.3905882754313441]

NOTE: Note that these numbers might differ for different Julia versions. To have stable streams across Julia versions use the StableRNGs.jl package.

3.5.3 Downloads

We’ll also cover the standard library’s Downloads module. It will be really brief because we will only be covering a single function named download.

Suppose you want to download a file from the internet to your local storage. You can accomplish this with the download function. The first and only required argument is the file’s url. You can also specify as a second argument the desired output path for the downloaded file (don’t forget the filesystem best practices!). If you don’t specify a second argument, Julia will, by default, create a temporary file with the tempfile function.

Let’s load the Downloads module:

  1. using Downloads

For example, let’s download our JuliaDataScience GitHub repository Project.toml file. Note that download function is not exported by Downloads module, so we have to use the Module.function syntax. By default, it returns a string that holds the file path for the downloaded file:

  1. url = "https://raw.githubusercontent.com/JuliaDataScience/JuliaDataScience/main/Project.toml"
  2. my_file = Downloads.download(url) # tempfile() being created
  1. /tmp/jl_ot4xCNapOh

With readlines, we can look at the first 4 lines of our downloaded file:

  1. readlines(my_file)[1:4]
  1. 4-element Vector{String}:
  2. "name = \"JDS\""
  3. "uuid = \"6c596d62-2771-44f8-8373-3ec4b616ee9d\""
  4. "authors = [\"Jose Storopoli\", \"Rik Huijzer\", \"Lazaro Alonso\"]"
  5. ""

NOTE: For more complex HTTP interactions such as interacting with web APIs, see the HTTP.jl package.

3.5.4 Project Management

One last thing from Julia’s standard library for us to cover is the Pkg module. As described in Section 2.2, Julia offers a built-in package manager, with dependencies and version control tightly controlled, manageable, and replicable.

Unlike traditional package managers, which install and manage a single global set of packages, Julia’s package manager is designed around “environments”: independent sets of packages that can be local to an individual project or shared between projects. Each project maintains its own independent set of package versions.

3.5.4.1 Project.toml and Manifest.toml

Inside every project environment there is a simple setup involving .toml files in a folder. The folder, in this context, can be perceived as a “project” folder. The project environment is derived on two .toml files:

  • Project.toml: higher-level description of the project environment with the top-level package list.
  • Manifest.toml: lower-level description of the project environment with the full dependencies list and their versions. This file is machine-generated, which means that users are not encouraged to edit it.

3.5.4.2 Creating Project Environments

In order to create a new project environment, you can enter the Pkg REPL mode by typing ] (right-bracket) in the Julia REPL:

  1. julia>]

Then it becomes the Pkg REPL mode:

  1. (@v1.8) pkg>

Here we can see that the REPL prompts changes from julia> to pkg>. There’s also additional information inside the parentheses regarding which project enviroment is currently active, (@v1.8). The v1.8 project environment is the default environment for your currently Julia installation (which in our case is Julia version 1.8.X).

NOTE: You can see a list of available commands in the Pkg REPL mode with the help command.

Julia has separate default environments for each minor release, the Xs in the 1.X Julia version. Anything that we perform in this default environment will impact any fresh Julia session on that version. Hence, we need to create a new environment by using the activate command:

  1. (@v1.8) pkg> activate .
  2. Activating project at `~/user/folder`
  3. (folder) pkg>

This activates a project environment in the directory that your Julia REPL is running. In my case this is located at ~/user/folder. Now we can start adding packages to our project environment with the add command in the Pkg REPL mode:

  1. (folder) pkg> add DataFrames
  2. Updating registry at `~/.julia/registries/General.toml`
  3. Resolving package versions...
  4. Updating `~/user/folder/Project.toml`
  5. [a93c6f00] + DataFrames v1.4.3
  6. Updating `~/user/folder/Manifest.toml`
  7. [34da2185] + Compat v4.4.0
  8. [a8cc5b0e] + Crayons v4.1.1
  9. [9a962f9c] + DataAPI v1.13.0
  10. [a93c6f00] + DataFrames v1.4.3
  11. [864edb3b] + DataStructures v0.18.13
  12. [e2d170a0] + DataValueInterfaces v1.0.0
  13. [59287772] + Formatting v0.4.2
  14. [41ab1584] + InvertedIndices v1.1.0
  15. [82899510] + IteratorInterfaceExtensions v1.0.0
  16. [b964fa9f] + LaTeXStrings v1.3.0
  17. [e1d29d7a] + Missings v1.0.2
  18. [bac558e1] + OrderedCollections v1.4.1
  19. [2dfb63ee] + PooledArrays v1.4.2
  20. [08abe8d2] + PrettyTables v2.2.1
  21. [189a3867] + Reexport v1.2.2
  22. [66db9d55] + SnoopPrecompile v1.0.1
  23. [a2af1166] + SortingAlgorithms v1.1.0
  24. [892a3eda] + StringManipulation v0.3.0
  25. [3783bdb8] + TableTraits v1.0.1
  26. [bd369af6] + Tables v1.10.0
  27. [56f22d72] + Artifacts
  28. [2a0f44e3] + Base64
  29. [ade2ca70] + Dates
  30. [9fa8497b] + Future
  31. [b77e0a4c] + InteractiveUtils
  32. [8f399da3] + Libdl
  33. [37e2e46d] + LinearAlgebra
  34. [56ddb016] + Logging
  35. [d6f4376e] + Markdown
  36. [de0858da] + Printf
  37. [3fa0cd96] + REPL
  38. [9a3f8284] + Random
  39. [ea8e919c] + SHA v0.7.0
  40. [9e88b42a] + Serialization
  41. [6462fe0b] + Sockets
  42. [2f01184e] + SparseArrays
  43. [10745b16] + Statistics
  44. [8dfed614] + Test
  45. [cf7118a7] + UUIDs
  46. [4ec0a83e] + Unicode
  47. [e66e0078] + CompilerSupportLibraries_jll v0.5.2+0
  48. [4536629a] + OpenBLAS_jll v0.3.20+0
  49. [8e850b90] + libblastrampoline_jll v5.1.1+0

From the add output, we can see that Julia automatically creates both the Project.toml and Manifest.toml files. In the Project.toml, it adds a new package to the proejct environment package list. Here are the contents of the Project.toml:

  1. [deps]
  2. DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

This is a .toml file where:

  • [deps]: a TOML table (also know as hash tables or dictionaries)
  • DataFrames: a key in the TOML deps table; this is the name of the package
  • "a93c6f00-e57d-5684-b7b6-d8193f3e46c0": the value for the DataFrames key; this is the universally unique identifier (UUID) of the package.

Let’s also take a peek into the Manifest.toml. Here we will truncate the output since it is a big machine-generated file:

  1. # This file is machine-generated - editing it directly is not advised
  2. julia_version = "1.8.3"
  3. manifest_format = "2.0"
  4. project_hash = "376d427149ea94494cc22001edd58d53c9b2bee1"
  5. [[deps.Artifacts]]
  6. uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
  7. ...
  8. [[deps.DataFrames]]
  9. deps = ["Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrettyTables", "Printf", "REPL", "Random", "Reexport", "SnoopPrecompile", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"]
  10. git-tree-sha1 = "0f44494fe4271cc966ac4fea524111bef63ba86c"
  11. uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
  12. version = "1.4.3"
  13. ...
  14. [[deps.libblastrampoline_jll]]
  15. deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
  16. uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
  17. version = "5.1.1+0"

The three dots above (...) represents truncated output. First, the Manifest.toml presents us a comment saying that it is machine-generated and discouragin editing it directly. Then, there are entries for the Julia version (julia_version), Manifest.toml format version (manifest_format), and project environment hash (project_hash). Finally, it proceeds with a TOML array of tables which are the double brackets entries ([[...]]). These entries stands for the dependencies of all packages necessary to create the environment described in the Project.toml. Therefore all of the DataFrames.jl‘s dependencies and its dependencies’ dependencies (and so on…) are listed here with their name, UUID, and version.

NOTE: Julia’s standard library module do not have a version key in the Manifest.toml because they are already specified by the Julia version (julia_version). This is the case for the Artifacts entry in the truncated Manifest.toml output above, since it is a module in Julia’s standard library.

We can keep adding as many packages as we like with the add command. To remove a package you can use the rm command in the Pkg REPL mode:

  1. (folder) pkg> rm DataFrames
  2. Updating `~/user/folder/Project.toml`
  3. [a93c6f00] - DataFrames v1.4.3
  4. Updating `~/user/folder/Manifest.toml`
  5. [34da2185] - Compat v4.4.0
  6. [a8cc5b0e] - Crayons v4.1.1
  7. [9a962f9c] - DataAPI v1.13.0
  8. [a93c6f00] - DataFrames v1.4.3
  9. [864edb3b] - DataStructures v0.18.13
  10. [e2d170a0] - DataValueInterfaces v1.0.0
  11. [59287772] - Formatting v0.4.2
  12. [41ab1584] - InvertedIndices v1.1.0
  13. [82899510] - IteratorInterfaceExtensions v1.0.0
  14. [b964fa9f] - LaTeXStrings v1.3.0
  15. [e1d29d7a] - Missings v1.0.2
  16. [bac558e1] - OrderedCollections v1.4.1
  17. [2dfb63ee] - PooledArrays v1.4.2
  18. [08abe8d2] - PrettyTables v2.2.1
  19. [189a3867] - Reexport v1.2.2
  20. [66db9d55] - SnoopPrecompile v1.0.1
  21. [a2af1166] - SortingAlgorithms v1.1.0
  22. [892a3eda] - StringManipulation v0.3.0
  23. [3783bdb8] - TableTraits v1.0.1
  24. [bd369af6] - Tables v1.10.0
  25. [56f22d72] - Artifacts
  26. [2a0f44e3] - Base64
  27. [ade2ca70] - Dates
  28. [9fa8497b] - Future
  29. [b77e0a4c] - InteractiveUtils
  30. [8f399da3] - Libdl
  31. [37e2e46d] - LinearAlgebra
  32. [56ddb016] - Logging
  33. [d6f4376e] - Markdown
  34. [de0858da] - Printf
  35. [3fa0cd96] - REPL
  36. [9a3f8284] - Random
  37. [ea8e919c] - SHA v0.7.0
  38. [9e88b42a] - Serialization
  39. [6462fe0b] - Sockets
  40. [2f01184e] - SparseArrays
  41. [10745b16] - Statistics
  42. [8dfed614] - Test
  43. [cf7118a7] - UUIDs
  44. [4ec0a83e] - Unicode
  45. [e66e0078] - CompilerSupportLibraries_jll v0.5.2+0
  46. [4536629a] - OpenBLAS_jll v0.3.20+0
  47. [8e850b90] - libblastrampoline_jll v5.1.1+0

NOTE: Julia’s Pkg REPL mode supports autocompletion with <TAB>. You can, for example, in the above command start typing rm DataF<TAB> and it will autocomplete to rm DataFrames.

We can see that rm DataFrames undoes add DataFrame by removing entries in both Project.toml and Manifest.toml.

3.5.4.3 Sharing Project Environments

Once you have a project environment with both the Project.toml and Manifest.toml files, you can share it with any user to have a perfectly reproducible project environment.

Now let’s cover the other end of the process. Suppose you received a Project.toml and a Manifest.toml from someone.

How would you proceed to instantiate a Julia project environment?

It is a simple process:

  1. Put the Project.toml and a Manifest.toml files into a folder.
  2. Open a Julia REPL in that folder and activate it as a project environment with ]activate.
  3. Instantiate the environment with the ]instantiate command.

That’s it! Once the project environment finished downloading and instantiating the dependencies listed in the Project.toml and Manifest.toml files, you’ll have an exact copy of the project environment sent to you.

NOTE: You can also add [compat] bounds in the Project.toml to specify which package versions your project environment is compatible with. This is an advanced-user functionality which we will not cover. Take a look at the Pkg.jl standard library module documentation on compatibility. For people new to Julia, we recommend sharing both Project.toml and Manifest.toml for a fully reproducible environment.

3.5 Julia Standard Library - 图1 Support this project
CC BY-NC-SA 4.0 Jose Storopoli, Rik Huijzer, Lazaro Alonso