Engee documentation

Working with Julia packages

Julia packages are an organised set of ready-made functions, classes and objects for various tasks. Julia packages can be installed with Pkg package manager and used in your projects. If you need a clearer separation between user and system packages, use EngeePkg.

In Engee, working with Julia packages is also done via the built-in Pkg package manager using two workspace tools - command line img 41 1 2 and script editor img41 1.

When working with a large number of packages, it is convenient to use the script editor, which does not require reinitialisation after calling Pkg. The command line is convenient if you are more used to working with code outside the script editor interface and with a small number of packages.

A detailed description of working with the Pkg package manager can be found at Pkg.

Principle of working with packages

  1. Find the exact name of the package you are interested in. The Julia ecosystem contains more than ten thousand packages registered in a common registry, which can make it very difficult to find the right package. To optimise your search, we recommend consulting the following sources:

    • Programming - Engee section with full documentation on Julia in Russian.

    • JuliaHub - a service for searching all registered documentation of open source packages with the ability to sort by tags and keywords.

    • Julia Packages - an online resource for searching, exploring and browsing Julia packages with the ability to set filters by category, popularity and date.

    • Julia.jl is the main repository of packages for the Julia programming language. This repository is hosted on the GitHub platform and contains many useful packages and tools developed by the community to work with the Julia language.

  2. Choose a tool to work with packages - command line or script editor depending on your tasks.

  3. Initialise package handling in Julia by adding the Pkg package manager. The syntax for adding a manager differs depending on the tool you choose.

  4. Add packages using the add command to your environment to use them in your project. The syntax for adding packages differs depending on the selected tool.

  5. Load the package into the namespace and access its specific elements using the using and import operators. You can also add your own packages.

  6. If necessary, find out the status of the package with status, check which packages are loaded into Engee RAM and remove unwanted ones with remove or rm (the syntax depends on the selected tool).

Detailed information about working with packages is given below.

Julia packages on the command line

To install a new package on the Engee command line, left-click in the code entry area and click the closing square bracket ]. This will switch the command line to work with the package manager. The line will change from engee> to pkg>:

pkg>

In package manager mode, use the add command to add the package:

add Example

You can add multiple packages at the same time by listing their names separated by commas, for example:

add Example, Plots, Pluto

The remove command or its abbreviated version rm is used to remove a package:

remove Pluto
Package deletion output
Updating `/user/.project/Project.toml`
  [c3e4b0f8] - Pluto v0.19.38
    Updating `/user/.project/Manifest.toml`
  [5218b696] - Configurations v0.17.6
  [e2d170a0] - DataValueInterfaces v1.0.0
  [21656369] - ExpressionExplorer v1.0.0
  [55351af7] - ExproniconLite v0.10.5
  [fb4132e2] - FuzzyCompletions v0.5.3
  [ac1192a8] - HypertextLiteral v0.9.5
  [82899510] - IteratorInterfaceExtensions v1.0.0
  [0e77f7df] - LazilyInitializedFields v1.2.2
  [6c6e2e6c] - MIMEs v0.1.4
  [36869731] - Malt v1.1.1
  [99f44e22] - MsgPack v1.2.0
  [c3e4b0f8] - Pluto v0.19.38
  [91cefc8d] - PrecompileSignatures v3.0.3
  [aea7be01] - PrecompileTools v1.2.0
  [2792f1a3] - RegistryInstances v0.1.0
  [3783bdb8] - TableTraits v1.0.1
  [bd369af6] - Tables v1.10.0
  [410a4b4d] - Tricks v0.1.6

If necessary, you can remove more than one package at a time by listing their names separated by commas:

remove Pluto, Plots, Example

Attempting to remove a non-existent package will result in an error:

Error output
 The following package names could not be resolved:
* Имя пакета (not found in project or manifest)
To exit the pkg> package manager mode, left-click in the code entry area and click Backspace. This will return you to the primary view of the engee> command line.

Julia packages in the script editor

To install a new package in the Engee interactive script, in the code section, import Pkg with the import Pkg command, and then run Pkg.add("Package Name"). For example, the code section to add the Example package would look like this:

import Pkg
Pkg.add("Example")

After clicking the Start button img 1 1 2 on this section, the Pkg package manager will be imported and the Example package will be installed. Information about the progress of the package installation will be displayed automatically:

Resolving package versions...
Installed Example ─ v0.5.3
Updating `/user/start/Project.toml`
[7876af07] + Example v0.5.3
Updating `/user/start/Manifest.toml`
[7876af07] + Example v0.5.3

As with the command line, you can add multiple packages at once by listing their names with commas and adding square brackets to create an array of strings, for example:

Pkg.add(["Example", "Plots"])

To remove a package, use the rm command:

Pkg.rm("Example")

To delete multiple packages at the same time, the names are enumerated using commas and square brackets:

Pkg.rm(["Example", "Plots"])

The remove command is not defined in the script editor, although it is used on the command line. Attempting to invoke the command in the editor will generate an error:

`UndefVarError: `remove` not defined`
In the script editor, the Pkg package manager name and Julia package names are case sensitive and must start with a capital letter, otherwise you will get an error message.

Package Status

To find out which packages are installed and ready for usage, open a command prompt and do the following:

  1. Log in to the Pkg package manager via ].

  2. Type the command status:

pkg> status

After that you will see a list of installed packages and their version:

Package Status Display
pkg> status
Status `/user/.project/Project.toml`
⌅ [c3fe647b] AbstractAlgebra v0.27.8
⌅ [7d9f7c33] Accessors v0.1.27
⌅ [79e6a3ab] Adapt v3.5.0
⌅ [91a5bcdd] Plots v1.36.1
⌃ [c3e4b0f8] Pluto v0.19.36

The symbols and mean that there are new versions for packages:

  • - a newer version is available.

  • - a newer version is available, but there are compatibility conflicts with other packages.

You can also find out which packages are installed and ready for usage through the script editor:

  1. Type import Pkg if you have not done so previously.

  2. Type Pkg.status() to get the status of packages.

Downloading packages

Julia uses the import and using operators to load packages and provide access to their specific elements, such as functions, types, and variables:

  • using is used to load all exported names from a module and bind them to the current namespace. For example:

    using Statistics
    
    x = mean([1, 2, 3, 4, 5])
  • import - used to selectively import certain functions or variables from a module. Requires the module name to be specified before the function or variable name. Consequently, a function or variable not explicitly imported will not be available in the current environment. Example:

    import Statistics
    
    x = Statistics.mean([1, 2, 3, 4, 5])

Consider the advantages and limitations of operators:

  • The advantage of using is convenience. The code becomes more capacious, all functions and variables from modules are available in the current namespace.

  • Disadvantage of using - usage of using to load large modules with many functions and variables can affect performance and memory overflow.

  • The disadvantage of using is name conflict. using can cause name conflicts if multiple modules define functions or variables with the same name.

  • The advantage of import is that there is no name conflict.

  • The advantage of import is to reduce compilation time by avoiding the need to compile unnecessary code.

  • The disadvantage of import is code complexity.

Thus, the using operator is more suitable for small projects with an emphasis on convenience. The import operator is more suitable for large projects with an emphasis on selectivity and control over memory usage.