Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Julia 1.0 Programming Cookbook

You're reading from   Julia 1.0 Programming Cookbook Over 100 numerical and distributed computing recipes for your daily data science work?ow

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781788998369
Length 460 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Przemysław Szufel Przemysław Szufel
Author Profile Icon Przemysław Szufel
Przemysław Szufel
Bogumił Kamiński Bogumił Kamiński
Author Profile Icon Bogumił Kamiński
Bogumił Kamiński
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing and Setting Up Julia FREE CHAPTER 2. Data Structures and Algorithms 3. Data Engineering in Julia 4. Numerical Computing with Julia 5. Variables, Types, and Functions 6. Metaprogramming and Advanced Typing 7. Handling Analytical Data 8. Julia Workflow 9. Data Science 10. Distributed Computing 11. Other Books You May Enjoy

To get the most out of this book

Some understanding of Julia would be a bonus.

In this book, we use many Julia packages. Here, we provide an installation script for those packages.

This script can be also found in the GitHub repository in the cookbookconf.jl file.

All packages are installed and pinned in a concrete version that ensures that they will work correctly with the recipes given in the book. More information about managing packages can be found in the Managing Packages recipe in Chapter 1, Installing and Setting Up Julia.

If you do not pin the packages to the required version, they might still work, but it is possible that newer versions of some packages introduce non-compatible API changes, in which case the codes of the recipes might need small alterations to make them run.

We have divided packages into three groups:

  • Packages that do not depend on external software
  • Packages that can optionally depend on an external Anaconda Python installation
  • Packages that require external software to be run.

For each package group, we provide an installation script that installs exactly the same version that we have used in the book.

All the packages listed are installed by calling the following function:

using Pkg

function addandpin(spec)
Pkg.add(PackageSpec(; spec...))
Pkg.pin(spec.name)
end

Packages that do not depend on external software can be installed with the following commands:

pkg1 = [(name="StatsBase", version="0.26.0"),
(name="TimeZones", version="0.8.1"),
(name="BSON", version="0.2.1"),
(name="Revise", version="0.7.12"),
(name="Distributions", version="0.16.4"),
(name="Clp", version="0.5.0"),
(name="HTTP", version="0.7.1"),
(name="Gumbo", version="0.5.1"),
(name="StringEncodings", version="0.3.1"),
(name="ZMQ", version="1.0.0"),
(name="CodecZlib", version="0.5.0"),
(name="JSON", version="0.19.0"),
(name="BenchmarkTools", version="0.4.1"),
(name="JuliaWebAPI", version="0.5.0"),
(name="FileIO", version="1.0.2"),
(name="ProfileView", version="0.4.0"),
(name="StaticArrays", version="0.8.3"),
(name="ForwardDiff", version="0.9.0"),
(name="Optim", version="0.17.1"),
(name="JuMP", version="0.18.4"),
(name="JLD2", version="0.1.2"),
(name="XLSX", version="0.4.2"),
(name="Cbc", version="0.4.2"),
(name="DataFrames", version="0.14.1"),
(name="CSV", version="0.4.3"),
(name="DataFramesMeta", version="0.4.0"),
(name="Feather", version="0.5.0"),
(name="FreqTables", version="0.3.0"),
(name="OnlineStats", version="0.19.1"),
(name="MySQL", version="0.7.0"),
(name="Cascadia", version="0.4.0"),
(name="UnicodePlots", version="0.3.1"),
(name="ParallelDataTransfer", version="0.5.0")]]

foreach(addandpin, pkg1)

Packages that can optionally depend on an external Python Anaconda installation (refer to the Calling Python from Julia recipe in Chapter 8, Julia Workflow, for details) can be installed with the following commands:

pkg2 = [(name="Conda", version="1.0.2"),
(name="PyCall", version="1.18.4"),
(name="PyPlot", version="2.6.3"),
(name="Plots", version="0.20.5"),
(name="StatPlots", version="0.8.1")]

foreach(addandpin, pkg2)

Some packages require external software to be installed. This includes the RCall.jl, JDBC.jl, LibPQ.jl and Gurobi.jl packages. Before installing those packages, make sure that the required software is installed on your system. For the RCall.jl package, check the Calling R from Julia recipe in Chapter 8, Julia Workflow, for JDBC.jl and LibPQ.jl, check the Working with databases in Julia recipe, and for Gurobi.jl, check the Optimization using JuMP recipe; both recipes can be found in Chapter 9, Data Science. Once you make sure that all software dependencies are installed, you can use the following commands:

pkg3 = [(name="RCall", version="0.12.1"),
(name="JDBC", version="0.4.0"),
(name="LibPQ", version="0.5.0"),
(name="Gurobi", version="0.5.3")]

foreach(addandpin, pkg3)

Download the example code files

The example code files are organized in folders representing chapters and recipes. For each recipe, there is a commands.txt file that contains commands that should be typed-in by the reader. Every entry in this file is prepended by an appropriate prompt (example, $, julia>) to make sure that the user knows in which environment the command should be executed (typically the OS shell, the Julia command line). Most recipes also contain additional files, for example, source codes of Julia programs. A full list of files along with their contents is given in the Getting ready section of every recipe.

You can download the example code files for this book from your account at www.packt.com.If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Julia-1.0-Programming-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, path names, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

html, body, #map {
height: 100%;
margin: 0;
padding: 0
}

For each block of code, we explain how it should be used (for example, maybe it should be pasted into a file or executed on the console).

Any command-line input is written in bold and the command-line output is written in normal font:

julia> collect(1:5)
5-element Array{Int64,1}:
1
2
3
4
5

julia> sin(1)
0.8414709848078965

julia>

Code that is executed in an OS shell (for Linux or Windows) is indicated with the $ sign (for Windows, this will be C:\). You should write commands that follow this sign (without the sign itself). For example, this command would give information about files in a current working directory:

$ ls

All single commands passed to the Julia command line are prepended with the julia> prompt marker. For example, this is a minimal Julia session:

$ julia --banner=no
julia> 1+2
3

julia> exit()

$

We have started Julia from the OS shell using the julia command. Then, we have entered 1+2 in the Julia command line and Julia printed 3. Finally, we have entered exit() in Julia to terminate the the Julia command-line session and go back to the shell (so we have the shell $ prompt in the last line of the output). Please note that for the aforementioned blocks of code, separate, instructions might be given that might also include copying and pasting them to the console.

In several recipes, we also discuss non-standard prompts in the Julia command line (for example, package manager mode or shell mode). They are explained in the relevant recipes.

All examples in this book have been tested on Linux Ubuntu 18.04 LTS and Windows 10. Please note that users of other Linux distributions will need to update their scripts (for example, Linux distributions from the Red Hat family use yum instead of apt). Most Linux-related commands should also work on macOS; however, they have not been tested on this OS.

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image