100% found this document useful (4 votes)
836 views

Instant Download Clojure Data Analysis Cookbook 1st Edition Eric Rochester PDF All Chapters

Clojure

Uploaded by

cansumurksmj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
836 views

Instant Download Clojure Data Analysis Cookbook 1st Edition Eric Rochester PDF All Chapters

Clojure

Uploaded by

cansumurksmj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Download the full version of the ebook at ebookname.

com

Clojure Data Analysis Cookbook 1st Edition Eric


Rochester

https://ebookname.com/product/clojure-data-analysis-
cookbook-1st-edition-eric-rochester/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Clojure Data Analysis Cookbook 2nd Edition Eric Rochester

https://ebookname.com/product/clojure-data-analysis-cookbook-2nd-
edition-eric-rochester/

ebookname.com

Clojure Data Structures and Algorithms Cookbook 25 recipes


to deeply understand and implement advanced algorithms in
Clojure 1st Edition Rafik Naccache
https://ebookname.com/product/clojure-data-structures-and-algorithms-
cookbook-25-recipes-to-deeply-understand-and-implement-advanced-
algorithms-in-clojure-1st-edition-rafik-naccache/
ebookname.com

Haskell Data Analysis Cookbook 1st Edition Nishant Shukla

https://ebookname.com/product/haskell-data-analysis-cookbook-1st-
edition-nishant-shukla/

ebookname.com

EMQs for the MRCS Part A 1st Edition Sri G. Thrumurthy

https://ebookname.com/product/emqs-for-the-mrcs-part-a-1st-edition-
sri-g-thrumurthy/

ebookname.com
Epistemology 1st Edition Richard Fumerton

https://ebookname.com/product/epistemology-1st-edition-richard-
fumerton/

ebookname.com

Jedi Twilight Star Wars Coruscant Nights I 1st Printing


Edition Michael Reaves

https://ebookname.com/product/jedi-twilight-star-wars-coruscant-
nights-i-1st-printing-edition-michael-reaves/

ebookname.com

Effective Instructional Strategies 4th Edition Kenneth D.


Moore

https://ebookname.com/product/effective-instructional-strategies-4th-
edition-kenneth-d-moore/

ebookname.com

Measuring Society 1st Edition Chaitra H. Nagaraja

https://ebookname.com/product/measuring-society-1st-edition-chaitra-h-
nagaraja/

ebookname.com

Nanocarbons for Advanced Energy Storage 1st Edition


Xinliang Feng (Ed.)

https://ebookname.com/product/nanocarbons-for-advanced-energy-
storage-1st-edition-xinliang-feng-ed/

ebookname.com
Photographic multishot techniques high dynamic range super
resolution extended depth of field stitching 1st ed
Edition Gulbins
https://ebookname.com/product/photographic-multishot-techniques-high-
dynamic-range-super-resolution-extended-depth-of-field-stitching-1st-
ed-edition-gulbins/
ebookname.com
Clojure Data Analysis
Cookbook

Over 110 recipes to help you dive into the world of


practical data analysis using Clojure

Eric Rochester

BIRMINGHAM - MUMBAI
Clojure Data Analysis Cookbook

Copyright © 2013 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.

First published: March 2013

Production Reference: 1130313

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78216-264-3

www.packtpub.com

Cover Image by J.Blaminsky (milak6@wp.pl)


Credits

Author Project Coordinator


Eric Rochester Anugya Khurana

Reviewers Proofreaders
Jan Borgelin Mario Cecere
Thomas A. Faulhaber, Jr. Sandra Hopper
Charles M. Norton
Miki Tebeka Indexer
Monica Ajmera Mehta

Acquisition Editor
Erol Staveley Graphics
Aditi Gajjar

Lead Technical Editor


Dayan Hyames Production Coordinator
Nilesh R. Mohite

Technical Editors
Nitee Shetty Cover Work
Nilesh R. Mohite
Dennis John
About the Author

Eric Rochester enjoys reading, writing, and spending time with his wife and kids. When
he's not doing those things, he programs in a variety of languages and platforms, including
websites and systems in Python and libraries for linguistics and statistics in C#. Currently, he's
exploring functional programming languages, including Clojure and Haskell. He works at the
Scholars' Lab in the library at the University of Virginia, helping humanities professors and
graduate students realize their digitally informed research agendas.

I'd like to thank everyone. My technical reviewers—Jan Borgelin, Tom


Faulhaber, Charles Norton, and Miki Tebeka—proved invaluable. Also, thank
you to the editorial staff at Packt Publishing. This book is much stronger for
all of their feedbacks, and any remaining deficiencies are mine alone.

Thank you to Bethany Nowviskie and Wayne Graham. They've made the
Scholars' Lab a great place to work, with interesting projects, as well as
space to explore our own interests.

And especially I would like to thank Jackie and Melina. They've been
exceptionally patient and supportive while I worked on this project. Without
them, it wouldn't be worth it.
About the Reviewers

Jan Borgelin is a technology geek with over 10 years of professional software development
experience. Having worked in diverse positions in the field of enterprise software, he currently
works as a CEO and Senior Consultant for BA Group Ltd., an IT consultancy based in Finland.
For the past 2 years, he has been more actively involved in functional programming and as
part of that has become interested in Clojure among other things.

I would like to thank my family and our employees for tolerating my


excitement about the book throughout the review process.

Thomas A. Faulhaber, Jr., is principal of Infolace (www.infolace.com), a San


Francisco-based consultancy. Infolace helps clients from startups to global brands turn raw
data into information and information into action. Throughout his career, he has developed
systems for high-performance TCP/IP, large-scale scientific visualization, energy trading, and
many more.

He has been a contributor to, and user of, Clojure and Incanter since their earliest days. The
power of Clojure and its ecosystem (of both code and people) is an important "magic bullet" in
Tom's practice.
Charles Norton has over 25 years of programming experience, ranging from factory
automation applications and firmware to network middleware, and is currently a programmer
and application specialist for a Greater Boston municipality. He maintains and develops a
collection of software applications that support finances, health insurance, and water utility
administration. These systems are implemented in several languages, including Clojure.

Miki Tebeka has been shipping software for more than 10 years. He has developed a
wide variety of products from assemblers and linkers to news trading systems to cloud
infrastructures. He currently works at Adconion where he shuffles through more than 6 billion
monthly events. In his free time, he is active in several open source communities.
www.PacktPub.com

Support files, eBooks, discount offers and more


You might want to visit www.PacktPub.com for support files and downloads related to
your book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
TM

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.

Why Subscribe?
ff Fully searchable across every book published by Packt
ff Copy and paste, print and bookmark content
ff On demand and accessible via web browser

Free Access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface 1
Chapter 1: Importing Data for Analysis 7
Introduction 7
Creating a new project 8
Reading CSV data into Incanter datasets 9
Reading JSON data into Incanter datasets 11
Reading data from Excel with Incanter 12
Reading data from JDBC databases 13
Reading XML data into Incanter datasets 16
Scraping data from tables in web pages 19
Scraping textual data from web pages 23
Reading RDF data 26
Reading RDF data with SPARQL 29
Aggregating data from different formats 34
Chapter 2: Cleaning and Validating Data 41
Introduction 41
Cleaning data with regular expressions 42
Maintaining consistency with synonym maps 44
Identifying and removing duplicate data 45
Normalizing numbers 48
Rescaling values 50
Normalizing dates and times 51
Lazily processing very large data sets 54
Sampling from very large data sets 56
Fixing spelling errors 57
Parsing custom data formats 61
Validating data with Valip 64
Table of Contents

Chapter 3: Managing Complexity with Concurrent Programming 67


Introduction 68
Managing program complexity with STM 69
Managing program complexity with agents 73
Getting better performance with commute 75
Combining agents and STM 77
Maintaining consistency with ensure 79
Introducing safe side effects into the STM 82
Maintaining data consistency with validators 84
Tracking processing with watchers 87
Debugging concurrent programs with watchers 90
Recovering from errors in agents 91
Managing input with sized queues 93
Chapter 4: Improving Performance with Parallel Programming 95
Introduction 95
Parallelizing processing with pmap 96
Parallelizing processing with Incanter 100
Partitioning Monte Carlo simulations for better pmap performance 102
Finding the optimal partition size with simulated annealing 106
Parallelizing with reducers 110
Generating online summary statistics with reducers 114
Harnessing your GPU with OpenCL and Calx 116
Using type hints 120
Benchmarking with Criterium 123
Chapter 5: Distributed Data Processing with Cascalog 127
Introduction 128
Distributed processing with Cascalog and Hadoop 129
Querying data with Cascalog 132
Distributing data with Apache HDFS 134
Parsing CSV files with Cascalog 137
Complex queries with Cascalog 139
Aggregating data with Cascalog 142
Defining new Cascalog operators 143
Composing Cascalog queries 146
Handling errors in Cascalog workflows 149
Transforming data with Cascalog 151
Executing Cascalog queries in the Cloud with Pallet 152
Chapter 6: Working with Incanter Datasets 159
Introduction 159
Loading Incanter's sample datasets 160
ii
Table of Contents
Loading Clojure data structures into datasets 161
Viewing datasets interactively with view 163
Converting datasets to matrices 164
Using infix formulas in Incanter 166
Selecting columns with $ 168
Selecting rows with $ 170
Filtering datasets with $where 171
Grouping data with $group-by 174
Saving datasets to CSV and JSON 175
Projecting from multiple datasets with $join 177
Chapter 7: Preparing for and Performing Statistical Data Analysis
with Incanter 181
Introduction 182
Generating summary statistics with $rollup 182
Differencing variables to show changes 185
Scaling variables to simplify variable relationships 186
Working with time series data with
Incanter Zoo 189
Smoothing variables to decrease noise 192
Validating sample statistics with bootstrapping 194
Modeling linear relationships 197
Modeling non-linear relationships 200
Modeling multimodal Bayesian distributions 204
Finding data errors with Benford's law 207
Chapter 8: Working with Mathematica and R 211
Introduction 212
Setting up Mathematica to talk to Clojuratica for Mac OS X and Linux 212
Setting up Mathematica to talk to Clojuratica for Windows 216
Calling Mathematica functions from Clojuratica 218
Sending matrices to Mathematica from Clojuratica 219
Evaluating Mathematica scripts from Clojuratica 220
Creating functions from Mathematica 221
Processing functions in parallel in Mathematica 222
Setting up R to talk to Clojure 224
Calling R functions from Clojure 226
Passing vectors into R 227
Evaluating R files from Clojure 228
Plotting in R from Clojure 230

iii
Table of Contents

Chapter 9: Clustering, Classifying, and Working with Weka 233


Introduction 233
Loading CSV and ARFF files into Weka 234
Filtering and renaming columns in Weka datasets 236
Discovering groups of data using K-means clustering 239
Finding hierarchical clusters in Weka 245
Clustering with SOMs in Incanter 248
Classifying data with decision trees 250
Classifying data with the Naive Bayesian classifier 253
Classifying data with support vector machines 255
Finding associations in data with the Apriori algorithm 258
Chapter 10: Graphing in Incanter 261
Introduction 261
Creating scatter plots with Incanter 262
Creating bar charts with Incanter 264
Graphing non-numeric data in bar charts 266
Creating histograms with Incanter 268
Creating function plots with Incanter 270
Adding equations to Incanter charts 272
Adding lines to scatter charts 273
Customizing charts with JFreeChart 276
Saving Incanter graphs to PNG 278
Using PCA to graph multi-dimensional data 279
Creating dynamic charts with Incanter 282
Chapter 11: Creating Charts for the Web 285
Introduction 285
Serving data with Ring and Compojure 286
Creating HTML with Hiccup 290
Setting up to use ClojureScript 293
Creating scatter plots with NVD3 296
Creating bar charts with NVD3 302
Creating histograms with NVD3 305
Visualizing graphs with force-directed layouts 308
Creating interactive visualizations with D3 313
Index 317

iv
Preface
Data's everywhere! And, as it has become more pervasive, our desire to use it has grown
just as quickly. A lot hides in data: potential sales, users' browsing patterns, demographic
information, and many, many more things. There are insights we could gain and decisions we
could make better, if only we could find out what's in our data.

This book will help with that.

The programming language Clojure will help us. Clojure was first released in 2007 by Rich
Hickey. It's a member of the lisp family of languages, and it has the strengths and flexibility
that they provide. It's also functional, so Clojure programs are easy to reason with. And, it
has amazing features for working concurrently and in parallel. All of these can help us as we
analyze data while keeping things simple and fast.

Clojure's usefulness for data analysis is further improved by a number of strong libraries.
Incanter provides a practical environment for working with data and performing statistical
analysis. Cascalog is an easy-to-use wrapper over Hadoop and Cascading. Finally, when
we're ready to publish our results, ClojureScript, an implementation of Clojure that generates
JavaScript, can help us to visualize our data in an effective and persuasive way.

Moreover, Clojure runs on the Java Virtual Machine (JVM), so any libraries written for Java are
available too. This gives Clojure an incredible amount of breadth and power.

I hope that this book will give you the tools and techniques you need to get answers from
your data.
Preface

What this book covers


Chapter 1, Importing Data for Analysis, will cover how to read data from a variety of sources,
including CSV files, web pages, and linked semantic web data.

Chapter 2, Cleaning and Validating Data, will present strategies and implementations for
normalizing dates, fixing spelling, and working with large datasets. Getting data into a useable
shape is an important, but often overlooked, stage of data analysis.

Chapter 3, Managing Complexity with Concurrent Programming, will cover Clojure's


concurrency features and how we can use them to simplify our programs.

Chapter 4, Improving Performance with Parallel Programming, will cover using Clojure's
parallel processing capabilities to speed up processing data.

Chapter 5, Distributed Data Processing with Cascalog, will cover using Cascalog as a wrapper
over Hadoop and the Cascading library to process large amounts of data distributed over
multiple computers. The final recipe in this chapter will use Pallet to run a simple analysis on
Amazon's EC2 service.

Chapter 6, Working with Incanter Datasets, will cover the basics of working with Incanter
datasets. Datasets are the core data structure used by Incanter, and understanding them is
necessary to use Incanter effectively.

Chapter 7, Preparing for and Performing Statistical Data Analysis with Incanter, will cover
a variety of statistical processes and tests used in data analysis. Some of these are quite
simple, such as generating summary statistics. Others are more complex, such as performing
linear regressions and auditing data with Benford's Law.

Chapter 8, Working with Mathematica and R, will talk about setting up Clojure to talk to
Mathematica or R. These are powerful data analysis systems, and sometimes we might want
to use them. This chapter will show us how to get these systems to work together, as well as
some tasks we can do once they are communicating.

Chapter 9, Clustering, Classifying, and Working with Weka, will cover more advanced machine
learning techniques. In this chapter, we'll primarily use the Weka machine learning library, and
some recipes will discuss how to use it and the data structures its built on, while other recipes
will demonstrate machine learning algorithms.

Chapter 10, Graphing in Incanter, will show how to generate graphs and other visualizations
in Incanter. These can be important for exploring and learning about your data and also for
publishing and presenting your results.

Chapter 11, Creating Charts for the Web, will show how to set up a simple web application
to present findings from data analysis. It will include a number of recipes that leverage the
powerful D3 visualization library.

2
Preface

What you need for this book


One piece of software required for this book is the Java Development Kit (JDK), which you can
get from http://www.oracle.com/technetwork/java/javase/downloads/index.
html. The JDK is necessary to run and develop on the Java platform.

The other major piece of software that you'll need is Leiningen 2, which you can download
and install from https://github.com/technomancy/leiningen. Leiningen 2 is a tool
for managing Clojure projects and their dependencies. It's quickly becoming the de facto
standard project tool in the Clojure community.

Throughout this book, we'll use a number of other Clojure and Java libraries, including Clojure
itself. Leiningen will take care of downloading these for us as we need them.

You'll also need a text editor or integrated development environment (IDE). If you already
have a text editor that you like, you can probably use it. See http://dev.clojure.org/
display/doc/Getting+Started for tips and plugins for using your particular favorite
environment. If you don't have a preference, I'd suggest looking at using Eclipse with
Counterclockwise. There are instructions for getting this set up at http://dev.clojure.
org/display/doc/Getting+Started+with+Eclipse+and+Counterclockwise.

That is all that's required. However, at various places throughout the book, some recipes will
access other software. The recipes in Chapter 8, Working with Mathematica and R, that relate
to Mathematica will require Mathematica, obviously, and those that relate to R, will require
that. However, these programs won't be used in the rest of the book, and whether you're
interested in these recipes might depend on whether you already have this software available.

Who this book is for


This book is for programmers or data scientists who are familiar with Clojure and want to use
it in their data analysis processes. This isn't a tutorial on Clojure—there are already a number
of excellent introductory books out there—so you'll need to be familiar with the language;
however, you don't need to be an expert at it.

Likewise, you don't need to be an expert on data analysis, although you should probably be
familiar with its tasks, processes, and techniques. While you might be able to glean enough
from these recipes to get started, to be truly effective, you'll want to get a more thorough
introduction to this field.

Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of
information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: " We just need to make sure that the clojure.
string/upper-case function is available."

3
Preface

A block of code is set as follows:


(defn fuzzy=
"This returns a fuzzy match."
[a b]
(let [dist (fuzzy-dist a b)]
(or (<= dist fuzzy-max-diff)
(<= (/ dist (min (count a) (count b)))
fuzzy-percent-diff))))

When we wish to draw your attention to a particular part of a code block, the relevant lines or
items are set in bold:
[ring.middleware.file-info :only (wrap-file-info)]
[ring.middleware.stacktrace :only (wrap-stacktrace)]
[ring.util.response :only (redirect)]
[hiccup core element page]
[hiccup.middleware :only (wrap-base-url)]))

Any command-line input or output is written as follows:


$ lein cljsbuild auto
Compiling ClojureScript.
Compiling "resources/js/scripts.js" from "src-cljs"...
Successfully compiled "resources/js/script.js" in 4.707129 seconds.

New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "errors are found in the page
Agents and Asynchronous Actions in the Clojure documentation ".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or may have disliked. Reader feedback is important for us to develop
titles that you really get the most out of.

4
Preface

To send us general feedback, simply send an e-mail to feedback@packtpub.com, and


mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.

Downloading the example code


You can download the example code files for all Packt books you have purchased from your
account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit
http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you would report this to us. By doing so, you can save other
readers from frustration and help us improve subsequent versions of this book. If you find
any errata, please report them by visiting http://www.packtpub.com/submit-errata,
selecting your book, clicking on the errata submission form link, and entering the details of
your errata. Once your errata are verified, your submission will be accepted and the errata
will be uploaded on our website, or added to any list of existing errata, under the Errata
section of that title. Any existing errata can be viewed by selecting your title from
http://www.packtpub.com/support.

Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt,
we take the protection of our copyright and licenses very seriously. If you come across any
illegal copies of our works, in any form, on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions
You can contact us at questions@packtpub.com if you are having a problem with any
aspect of the book, and we will do our best to address it.

5
Importing Data for
1
Analysis
In this chapter, we will cover:

ff Creating a new project


ff Reading CSV data into Incanter datasets
ff Reading JSON data into Incanter datasets
ff Reading data from Excel with Incanter
ff Reading data from JDBC databases
ff Reading XML data into Incanter datasets
ff Scraping data from tables in web pages
ff Scraping textual data from web pages
ff Reading RDF data
ff Reading RDF data with SPARQL
ff Aggregating data from different formats

Introduction
There's not a lot of data analysis that we can do without data, so the first step in any project is
evaluating what data we have and what we need. And once we have some idea of what we'll
need, we have to figure out how to get it.
Importing Data for Analysis

Many of the recipes in this chapter and in this book use Incanter (http://incanter.org/)
to import the data and target Incanter datasets. Incanter is a library for doing statistical
analysis and graphics in Clojure, similar to R. Incanter may not be suitable for every task—later
we'll use the Weka library for clustering and machine learning—but it is still an important part
of our toolkit for doing data analysis in Clojure. This chapter has a collection of recipes for
gathering data and making it accessible to Clojure. For the very first recipe, we'll look at how
to start a new project. We'll start with very simple formats like comma-separated values (CSV)
and move into reading data from relational databases using JDBC. Then we'll examine more
complicated data sources, such as web scraping and linked data (RDF).

Creating a new project


Over the course of this book, we're going to use a number of third-party libraries and external
dependencies. We need a tool to download them and track them. We also need a tool to set
up the environment and start a read-eval-print-loop (REPL, or interactive interpreter), which
can access our code, or to execute our program.

We'll use Leiningen for that (http://leiningen.org/). This has become a standard
package automation and management system.

Getting ready
Visit the Leiningen site (http://leiningen.org/) and download the lein script. This will
download the Leiningen JAR file. The instructions are clear, and it's a simple process.

How to do it...
To generate a new project, use the lein new command, passing it the name of the project:
$ lein new getting-data
Generating a project called getting-data based on the 'default' template.
To see other templates (app, lein plugin, etc), try 'lein help new'.

Now, there will be a new subdirectory named getting-data. It will contain files with stubs
for the getting-data.core namespace and for tests.

Downloading the example code


You can download the example code files for all Packt books you have
purchased from your account at http://www.packtpub.com. If you
purchased this book elsewhere, you can visit http://www.packtpub.
com/support and register to have the files e-mailed directly to you.

8
Chapter 1

How it works...
The new project directory also contains a file named project.clj. This file contains
metadata about the project: its name, version, and license. It also contains a list of
dependencies that our code will use. The specifications it uses allows it to search Maven
repositories and directories of Clojure libraries (Clojars, https://clojars.org/) to
download the project's dependencies.
(defproject getting-data "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]])

In the Getting ready section of each recipe, we'll see what libraries we need to list in the
:dependencies section of this file.

Reading CSV data into Incanter datasets


One of the simplest data formats is comma-separated values (CSV). And it's everywhere. Excel
reads and writes CSV directly, as do most databases. And because it's really just plain text, it's
easy to generate or access it using any programming language.

Getting ready
First, let's make sure we have the correct libraries loaded. The project file of Leiningen
(https://github.com/technomancy/leiningen), the project.clj file, should
contain these dependencies (although you may be able to use more up-to-date versions):
:dependencies [[org.clojure/clojure "1.4.0"]
[incanter/incanter-core "1.4.1"]
[incanter/incanter-io "1.4.1"]]

Also, in your REPL or in your file, include these lines:


(use 'incanter.core
'incanter.io)

Finally, I have a file named data/small-sample.csv that contains the following data:
Gomez,Addams,father
Morticia,Addams,mother
Pugsley,Addams,brother
Wednesday,Addams,sister

9
Importing Data for Analysis

You can download this file from http://www.ericrochester.com/clj-data-


analysis/data/small-sample.csv. There's a version with a header row at http://
www.ericrochester.com/clj-data-analysis/data/small-sample-header.csv.

How to do it…
1. Use the incanter.io/read-dataset function:
user=> (read-dataset "data/small-sample.csv")
[:col0 :col1 :col2]
["Gomez" "Addams" "father"]
["Morticia" "Addams" "mother"]
["Pugsley" "Addams" "brother"]
["Wednesday" "Addams" "sister"]

2. If we have a header row in the CSV file, then we include :header true in the call to
read-dataset:

user=> (read-dataset "data/small-sample-header.csv" :header true)


[:given-name :surname :relation]
["Gomez" "Addams" "father"]
["Morticia" "Addams" "mother"]
["Pugsley" "Addams" "brother"]

How it works…
Using Clojure and Incanter makes a lot of common tasks easy. This is a good example of that.

We've taken some external data, in this case from a CSV file, and loaded it into an Incanter
dataset. In Incanter, a dataset is a table, similar to a sheet in a spreadsheet or a database
table. Each column has one field of data, and each row has an observation of data. Some
columns will contain string data (all of the columns in this example did), some will contain
dates, some numeric data. Incanter tries to detect automatically when a column contains
numeric data and coverts it to a Java int or double. Incanter takes away a lot of the pain
of importing data.

There's more…
If we don't want to involve Incanter—when you don't want the added dependency, for
instance—data.csv is also simple (https://github.com/clojure/data.csv).
We'll use this library in later chapters, for example, in the recipe Lazily processing very
large datasets of Chapter 2, Cleaning and Validating Data.

10
Chapter 1

See also
ff Chapter 6, Working with Incanter Datasets

Reading JSON data into Incanter datasets


Another data format that's becoming increasingly popular is JavaScript Object Notation
(JSON, http://json.org/). Like CSV, this is a plain-text format, so it's easy for programs
to work with. It provides more information about the data than CSV does, but at the cost of
being more verbose. It also allows the data to be structured in more complicated ways, such
as hierarchies or sequences of hierarchies.

Because JSON is a much fuller data model than CSV, we may need to transform the data.
In that case, we can pull out just the information we're interested in and flatten the nested
maps before we pass it to Incanter. In this recipe, however, we'll just work with fairly simple
data structures.

Getting ready
First, include these dependencies in the Leiningen project.clj file:
:dependencies [[org.clojure/clojure "1.4.0"]
[incanter/incanter-core "1.4.1"]
[org.clojure/data.json "0.2.1"]]

Use these libraries in our REPL interpreter or in our program:


(use 'incanter.core
'clojure.data.json)

And have some data. For this, I have a file named data/small-sample.json that looks
like the following:
[{"given_name": "Gomez",
"surname": "Addams",
"relation": "father"},
{"given_name": "Morticia",
"surname": "Addams",
"relation": "mother"}, …
]

You can download this data file from http://www.ericrochester.com/clj-data-


analysis/data/small-sample.json.

11
Importing Data for Analysis

How to do it…
Once everything's in place, this is just a one-liner, which we can execute at the REPL
interpreter:
user=> (to-dataset (read-json (slurp "data/small-sample.json")))
[:given_name :surname :relation]
["Gomez" "Addams" "father"]
["Morticia" "Addams" "mother"]
["Pugsley" "Addams" "brother"]

How it works…
Like all Lisps, Clojure is usually read from inside out, from right to left. Let's break it down.
clojure.core/slurp reads in the contents of the file and returns it as a string. This is
obviously a bad idea for very large files, but for small ones it's handy. clojure.data.json/
read-json takes the data from slurp, parses it as JSON, and returns native Clojure data
structures. In this case, it returns a vector of maps. maps.incanter.core/to-dataset
takes a sequence of maps and returns an Incanter dataset. This will use the keys in the maps as
column names and will convert the data values into a matrix. Actually, to-dataset can accept
many different data structures. Try (doc to-dataset) in the REPL interpreter or see the
Incanter documentation at http://data-sorcery.org/contents/ for more information.

Reading data from Excel with Incanter


We've seen how Incanter makes a lot of common data-processing tasks very simple; reading
an Excel spreadsheet is another example of this.

Getting ready
First, make sure that our Leiningen project.clj file contains the right dependencies:
:dependencies [[org.clojure/clojure "1.4.0"]
[incanter/incanter-core "1.4.1"]
[incanter/incanter-excel "1.4.1"]]

Also, make sure that we've loaded those packages into the REPL interpreter or script:
(use 'incanter.core
'incanter.excel)

12
Random documents with unrelated
content Scribd suggests to you:
“If you can’t, I can,” responded Weeks. “I know where to put my hand
on him.”
At that moment a door at the rear of the room (within a few feet of
the table at which they were seated, in fact) opened, and a man
entered. Weeks recognized him at once as Jim Leroyd; he had seen
him before, although he could claim no speaking acquaintance with
him.
Old Arad also saw and recognized the newcomer, and as the sailor
passed along the room, he caught sight of the old farmer.
“Why, dash my top lights!” he exclaimed, in surprise. “Ef here ain’t
Mr. Tarr!”
He stepped back to the table and grasped the old man’s hand most
cordially, at the same time casting a suspicious glance at Weeks. He
knew the ex-clerk by reputation, as Weeks knew him.
“Don’t ye be up ter any funny biz with this gentleman, Sneaky,” he
said, with a scowl. “He’s my friend.”
“Don’t you fret,” responded Weeks. “He and I were talking about his
nephew, Brandon Tarr, who was up to see you yesterday——”
Mr. Leroyd uttered a volley of choice profanity at this, and Arad was
greatly surprised.
“Came ter see yeou?” he gasped. “Er—erbout that matter we was a-
talkin’ of, Mr. Leroyd? Ye know I—I’m his legal guardeen——”
“Don’t ye be scared, Mr. Tarr,” said Weeks, who understood the
circumstances pretty well, “I can vouch for Jim, here, not playing you
false.”
“What do you know about it, anyway?” growled Jim uglily.
“Now, sit down and keep cool, Leroyd,” urged Weeks. “I know all
about it. I know about your little scheme to gobble the—the treasure
aboard the Silver Swan——”
“Sh!” exclaimed Leroyd fiercely. “You know too much, young feller.”
“No, I know just enough, and I’ll prove it to you.”
“I s’pose ye think ye kin force yer way inter this, but ye’re mistaken.
This is the private affair o’ Mr. Tarr an’ me, an’ I warn ye ter keep yer
nose out.”
He arose as he spoke, his fierce eyes fixed threateningly upon
Weeks’ impassive face.
“You come with me, Mr. Tarr, where we can talk the matter over
privately. We don’t want nothin’ o’ that swab.”
The red headed ex-clerk fairly laughed aloud at this.
“See here, Leroyd,” he said, still coolly: “you made a break for those
papers yesterday, I believe. What did you get?”
“Hey?” roared the sailor.
“I said that you made a break for those papers of Cale Wetherbee’s
yesterday,” repeated Weeks, slowly and distinctly. “Now, what did
you get?”
“Not a blamed thing,” responded the sailor frankly, after an instant’s
hesitation.
“That’s what I thought. I thought Cale Wetherbee took it altogether
too coolly if you had made a haul worth anything. Now, I could tell
you something, if I thought ’twould be worth my while.”
“What is it?”
“Do you know what the treasure hidden aboard the brig consists of?”
“No,” replied Leroyd shortly, while old Arad gazed from one to the
other in bewilderment.
“Well, I do,” declared Weeks.
“Ye do?”
“Sure. I heard that Wetherbee and the boy and old man Pepper
talking it over.”
“Who’s Pepper?” growled Leroyd.
“He’s the feller who is going to back ’em in this hunt for the brig. He’s
going to furnish the vessel and all.”
“Curses on the luck!” growled the sailor again.
Here old Arad interposed. The old man’s hands were trembling
violently, and his face was pale with excitement.
“We—we must stop ’em—they ain’t got no right ter do it,” he
sputtered. “Horace Tarr was my nevvy, an’ I’m the guardeen o’ that
boy. There hain’t nobody else got no right to go arter them
di’monds.”
“Diamonds!” exclaimed Leroyd. “Is that the treasure?”
“Ye—es,” replied Arad hesitatingly, looking at Weeks. “I—I found a
letter from this Wetherbee, the mate of the Silver Swan, an’ it says
so. Horace’s brother Anson got ’em in South Afriky.”
“Good for you, old feller,” said Leroyd admiringly. “Ye did take my
advice, didn’t ye?”
Old Arad rubbed his hands together as though washing them with
imaginary soap, and grinned.
“Yes, diamonds is the treasure,” Weeks rejoined calmly. “Now, you’ll
start right off to find the brig with Mr. Tarr here to back you with
money, eh, Leroyd?”
“Never ye mind what I’ll do,” returned Jim, uglily. “I tell ye this hain’t
none o’ your funeral, so you keep out of it, Sneaky.”
“Are you sure?” asked Weeks, with a tantalizing smile.
“Yes, I’m sure!” roared the enraged sailor.
“Well, don’t holler so loud,” the red haired one admonished him. “But
I think you’re mistaken.”
Leroyd glared at him like an angry bull dog but said nothing.
“Now I s’pose,” continued Weeks, cocking his eye at the smoke
begrimmed ceiling of the bar room, “that you expect to get a vessel
an’ go in pursuit of the Silver Swan; and that when you’ve got her
you’ll tow her in port, an’ you’ll have the salvage—that’ll be a pretty
good sum.”
“And the di’monds,” interjected Arad, with an avaricious chuckle.
“Oh, will you?” said Weeks with cool sarcasm. “That remains to be
seen. You’ll have the brig fast enough: but how’ll you get the
stones?”
“Why, ef we git the brig won’t the diamonds be aboard her?” queried
Arad.
“Yes, they will; but where will they be, aboard her? Can you tell me
that?”
Arad’s jaw fell and he stared blankly at the shrewd Weeks. Even
Leroyd was visibly moved by this statement.
“You don’t know where the diamonds are hidden,” continued Weeks,
pursuing his advantage. “You might tear that whole brig to pieces an’
not find ’em, but I know just where they are and I can put my hand
right on ’em!”
“You kin?” gasped old Arad.
“Is that straight, Sneaky?” demanded Leroyd, with interest.
Weeks nodded calmly.
“I believe you’re lying,” the sailor declared.
“Well you can think so if you want to,” said the ex-clerk, rising, “and
I’ll go now and find somebody to go in with me on this scheme, and
I’ll run my chances of getting to the brig first. You can have the old
hulk and welcome after I’ve been aboard her five minutes, Leroyd.
“But, if you’ll let me in on the ground floor of this,” he continued, “and
give me one third of all there is in it, why all right. If you don’t,
probably you’ll get nothing, while me and the other fellow’ll get it all,”
and Mr. Weeks smiled benignantly upon his audience.
CHAPTER XXIV
HOW A NEFARIOUS COMPACT WAS FORMED

“But yeou can’t do that!” cried old Arad Tarr, the first to break the
silence after Mr. Weeks had delivered what might be termed his
“ultimatum.” “There hasn’t anybody got airy right ter go arter them
di’monds, but them I send.”
“That is where you make an error, Mr. Tarr,” responded Weeks
cheerfully. “This is what is called ‘treasure trove;’ the fellow who gets
there first has the best right to it.”
“It ben’t so, is it?” whined the old man, appealing to Leroyd.
“Yes, I s’pose it is,” admitted the sailor, with a growl. “He’s got us
foul, old man.”
“Now, don’t talk that way, Leroyd,” exclaimed Weeks briskly. “We
three must strike hands and share evenly in this thing. You need me,
any way, though I can get along without either of you; for you know it
wouldn’t take me long to find a man to back me with a couple of
hundred dollars against the chance of winning thousands.”
“Well, you’re right,” said the sailor, seeing that it would be for his
advantage to make terms with “Sneaky Al,” as the red haired Weeks
was familiarly called.
“Two hundred dollars is an awful lot of money ter risk,” muttered old
Arad, knowing that he was the one who would be expected to furnish
the “sinews of war.”
“’Tain’t much compared with mebbe three hundred thousand dollars.
I heered Cap’n Tarr say, myself, that there was enough o’ them
di’monds, ter make a man fabulously rich,” responded Leroyd
quickly. “That’d be a clean hundred thousand for each of us.”
“But ef I furnish the money I’d oughter hev more o’ th’ returns,”
declared the farmer, who was quite as sharp as either of his
companions.
“Come, we won’t quarrel over that,” the sailor declared, rising again.
“But we want to talk this matter over where it’s more quiet like. I’ve
got a room here. Let’s go up to it, where we shan’t be disturbed.”
“Now you’re talking sense,” Weeks declared, rising gingerly from the
chair in which he had again seated himself.
At that instant Mr. Brady, who had been kept busy at the bar by
transient customers for the past half hour, called Leroyd over to him.
“Now, look a-here, Jim,” he said, in a hoarse aside, “wot be you an’
Sneaky Al up to? Dere ain’t goin’ ter be no game played on dat
countryman here, see? Ye got me inter ’nough trouble yest’day. Ef I
hadn’t a pull in dis ward, dey’d er—nabbed me, sure.”
“Don’t you fret, Jack,” responded Leroyd reassuringly. “We ain’t inter
any bunco business. The old man knows what he’s about, ef he
does look like a hay-seed. Ef he don’t do us, it’ll be lucky.”
“Well, what’s de game?” Brady demanded.
“Never you mind, old man. We’re just going up stairs for a private
confab, an’ ef things turn out right, I kin promise a cool hundred for
keeping your mouth shut. Savey?”
Brady nodded.
“I’m mum,” he said, with satisfaction. “On’y I don’t want dem cops
down on me ag’in, so mind yer eye.”
Armed with a bottle and glasses, Leroyd led the way into a small
room a good deal nearer the roof of the building, in which the New
England Hotel was located. His two companions, however, left the
sailor to dispose of the refreshments alone; the old farmer because
he had never used liquor in any shape at home, and Weeks because
he proposed to keep his brain perfectly clear that he might be sure to
retain the “whip hand” of the other conspirators.
It is not my purpose to report verbatim the plans of the three villains.
Let it suffice to say that after much discussion, and by virtue of
coaxings, threatenings, promises, and what not, the sailor and
Weeks (who saw at once that it would be for their mutual advantage
to play into each other’s hands) obtained old Arad Tarr’s consent to
furnish them with the sum of over two hundred dollars (and more if it
was found to be actually needed) with which to charter the vessel.
You may be sure that the two rascals never worked harder (with their
tongues) for two hundred dollars in their lives, for the amount looked
as large to old Arad as ten thousand would to almost any other man.
The plot of the conspirators likewise included the discovery of
Brandon’s whereabouts and his arrest on the charge of robbery, as
set forth in the warrant with which Arad supplied himself before he
left Rhode Island. This part of the scheme Weeks proposed to attend
to.
Then, with a great deal of flourish and legal formula, the astute Mr.
Weeks drew up a most wonderful document (he was well versed in
legal phrases), which bound each of the three, Arad Tarr, James
Leroyd, and Alfred Weeks, to a co-partnership, the object of which
was to seek and obtain the floating hulk of the Silver Swan, and the
treasure thereon, the profit of the venture to be divided equally
between them, excepting the sum of one thousand dollars which was
to go to Arad Tarr under any circumstances. And, of course, the
document wasn’t worth the paper on which it was written.
But the old man didn’t know this. He was a great worshiper of the
law, and he trusted in the legality of the paper to hold his partners to
their promises. He lost sight, however, of the fact that the two men
were going together on the quest for the Silver Swan, and that he—
well, he was to stay at home, and wait. Waiting isn’t very hard work,
to be sure; but it is terribly wearing.
These several things having been accomplished, and it being long
past noon, the conspirators went their different ways—old Arad to
interview the brokerage firm of Bensell, Bensell & Marsden, which,
he was sure, was cheating him out of his dividends: Weeks to hunt
up a scaly friend of his to serve the warrant upon unsuspicious
Brandon; and Leroyd to look about for a vessel which could be
converted to their purpose in the shortest possible time.
And now, let us return to Brandon and his two good friends, Caleb
Wetherbee and Adoniram Pepper, and find out how much progress
they have made in the quest of the Silver Swan.
CHAPTER XXV
UNCLE ARAD MAKES AN ANNOUNCEMENT

If Caleb Wetherbee passed as sleepless a night as did his young


friend, Brandon, he showed no signs of it when he appeared the next
morning. They were a very jolly party indeed at the breakfast table,
for the old sailor had recovered, to some extent at least, his
equanimity when in the presence of Miss Frances.
“Now, Caleb, have you decided to accept my offer of last evening?”
Adoniram inquired, as they arose after the meal.
“Let’s see the steamer,” returned the sailor, noncommittally; so the
merchant and his two guests went down to the docks at once.
To a person who has never seen a whaleback steamer, the first view
of one is certainly a most surprising sight. He is at once reminded of
Jules Verne’s great story of the Nautilus, the wonderful steel ship
which could sail equally well below and upon the surface of the
ocean.
Number Three was more than two hundred feet in length, and was
shaped like a huge cigar, the blunt end, oddly enough, being the
bow. This blunt “nose” is what suggested the term “pig,” as applied to
the whalebacks when first they appeared on the Great Lakes.
At the forward end of the steamer a turret arose from the curved
deck, furnished with one of the American Ship Windlass Co.’s steam
windlasses (with the capstan above), and with hand steering gear,
the shaft and hub of the wheel being of brass to avoid affecting the
compass.
The cabin aft, which was fifteen feet above the deck, and therefore
presented a most astonishing appearance, was supported by two
turrets, and several strong ventilating pipes, the latter connecting
with the engine room, fire hold, and cargo hold.
A low rail ran from bow to stern of the steamer, on either side,
inclosing the turrets within its shelter, thus making it possible for the
crew to go from the aft to the forward turrets.
The deck, however, was so curved that the feat would not be easy to
perform in rough weather, if the whaleback did roll as do other
vessels.
“Ye call that a steamer, do ye?” demanded Caleb, in disgust, when
he first caught sight of Number Three; but after he had gone aboard,
and seen and understood the advantages the whaleback possessed
over the other seagoing craft, he no longer scoffed.
Adoniram first led them to the officers’ quarters. These were finished
in oak, and furnished almost as sumptuously as the cabin of a fancy
yacht. The suite contained a dining room of comfortable size, and a
chart room and offices on the port side of the cabin.
Below deck were the quarters of the crew, forward and aft, and they
were as comfortable as those on a palatial ocean steamship.
“It’s a wonderful boat,” Brandon declared, as they examined the
engine.
“It is that,” the ship owner assented. “I paid a pretty penny for her,
but she’s worth it—every cent. She’ll outride any gale that ever blew,
as long as you keep her in deep water. ’Twould be hard to sink her.
“In the matter of ballast,” he continued, “there are arrangements for
carrying eight hundred ton of water—water is used altogether for
ballast in these whalebacks. Then the engines are of the newest
build, too, you see.
“The steam is generated from these two steel boilers, each eleven
and a half feet in diameter by the same in length, possessing a
working pressure of one hundred and twenty-five pounds. If the
engine goes back on you, you will have to get out the oars and row
ashore, for there is no chance for raising a sail,” and the jolly ship
owner laughed good naturedly.
“Well, I’ve been to sea on a good many craft—most anything that
would float, in fact, from a torpedo boat to a Chinese junk—but this
takes the bun,” Caleb declared as they stepped upon the dock again.
“Then I take it you’ll try your hand at this?” Adoniram asked slily.
“Oh, yes, I s’ppose so, Pepperpod—and the boy, too. By the way,
does Lawrence Coffin know anything about this craft?”
“He went to West Superior (where she was built) and came down in
her,” declared the merchant.
“It’s all right, then. He’ll know what to do if we get to sea and the
blamed thing should roll over.”
But despite the fact that he scoffed at the vessel, Caleb set to work
with his customary energy to make ready for the voyage.
The ship owner gave him carte blanche to provision the whaleback
and secure the crew. The engineers and firemen were already
engaged and the work of making ready for sea went on rapidly.
Caleb being a worker himself, expected a good deal of everybody
about him and Brandon found himself with plenty to do during the
next two days. He ran errands, and bought provisions under the old
sailor’s directions, and saw to the storing away of the articles
purchased.
On the morning of the third day, however, came an interruption, and
one which promised to be most serious.
In these times of hurried preparation Caleb and his young second
mate made the Water Street office of Adoniram Pepper & Co. their
headquarters. They were in and out of the place a score of times a
day to the satisfaction of Adoniram, but, if the truth were told, to the
great annoyance of the solemn faced young man whom Mr. Marks
had sent up from the other office to take the place of the departed
Weeks.
About ten o’clock on this forenoon Brandon ran in to see if he could
find Caleb, as that individual was not at the dock where lay the
whaleback, and where the boy had expected to meet him.
“Where do you suppose he has gone?” Don asked of Mr. Pepper,
who, good soul, seemed to have no other business on hand but the
getting ready of the steamer.
“I don’t know, I’m sure. You’d better sit down, my boy, and wait for
him,” advised Adoniram kindly. “He’s sure to turn up here, first or
last.”
So Brandon sat down, striving to stifle his impatience. He had not
waited ten minutes, however, when the door of the outer office was
opened, and somebody entered.
“Here he is now,” exclaimed the youth, thinking he heard Caleb’s
voice.
He threw open the door between the two offices, gave one glance
into the apartment beyond, and staggered to the nearest chair in
utter amazement.
“Great Peter! it’s Uncle Arad!” he gasped, in answer to Adoniram’s
questioning exclamation, and the next instant Uncle Arad himself
appeared at the open portal of the private office.
“Thar ye air, ye young reskil!” exclaimed the old man, shaking his
bony forefinger at the youth.
Behind him was another man—a clean shaven, foxy looking fellow,
who, when old Arad had pointed the boy out, stepped quickly into the
room.
“Well, well!” exclaimed Brandon, recovering in part from his surprise.
“Who’d have thought of seeing you here, Uncle Arad!”
“Not yeou, I warrant!” cackled the old man shrilly. “I s’pose ye
thought ye c’d git off scott free with yer ill gotten gains, didn’t ye?”
“What?”
Brandon’s face flamed up redly, and he sprang to his feet in rage.
“What do you mean?” he demanded.
“Don’t ye let him escape, officer!” the farmer exclaimed, shrinking
back. “He’s quick’s a cat.”
But here Adoniram took a hand in the proceedings.
“I should like to know, sir, what you mean by this?” he said, his gray
eyes flashing behind the tip tilted eye glasses. “Brandon is under my
care, sir, and I will not allow such remarks to be addressed to him.”
No one would have believed that it was the jolly Adoniram, to see his
face now. The habitual smile had disappeared entirely.
“I dunno who yeou be,” Arad replied defiantly; “but I kin tell ye who I
be, purty quick. I’m Arad Tarr; this young reskil here is my nevvy; an’
I’m his nateral an’ lawful guardeen.”
“Ah!” said Mr. Pepper, with quiet sarcasm. “So you are his guardian,
are you? How long since?”
“How long since?” repeated the old man, in a rage. “I’ll show ye! I’ve
allus been his guardeen—leastways, since his pa died.”
“Which occurred a little over two months ago,” said Adoniram briefly.
“Now, Mr. Tarr, for I suppose that is your name, where are your
papers making you this lad’s guardian? Who appointed you?”
“I’m his nateral guardeen now,” old Arad declared slowly; “but I’m
goin’ to be ’p’inted by the court.”
“What court?”
“The Court o’ Probate, o’ Scituate, R. I.,” responded the farmer
pompously.
“Well, I think not,” said Adoniram, who was probably never more
angry in his life than at that moment. “You have made a slight
mistake, Mr. Tarr.”
“Hey?” returned the farmer, growing red in the face, and looking
daggers at the little merchant.
“I say you have made a slight mistake. You will not be appointed
guardian of Brandon, by any court in the land. Did it ever occur to
you that Captain Horace Tarr might have made a will?”
“A will?” gasped the old man.
“Yes, sir, a will.”
“But he didn’t hev nothin’ ter will, ’ceptin——”
“Well, excepting what?” Mr. Pepper demanded, as the other
hesitated.
“Nothin’.”
“Well, he did have something to will, and he appointed me joint
guardian, with another gentleman, and you, Mr. Tarr, are not the
party named to assist me. We have already made application in the
New York courts to have the appointment allowed and the will has
been presented for probate.”
“I—I don’t believe it!” shouted Arad.
“You’re not obliged to. But that doesn’t affect the facts of the case,
just the same.”
For a moment the farmer was quite nonplussed: but then he looked
at the man he had brought with him again, and his faith revived.
“Ye can’t escape me this way, ye young varmint!” he exclaimed,
turning upon Brandon as though he were some way at fault for the
wrecking of his plans. “Mebbe I hain’t your guardeen, but I’ve power
’nough right here ter lug ye back ter Scituate an’ put yer through fur
stealin’ that money.”
“What money?” demanded Brandon, white with rage. “To what do
you refer?”
“That fifty dollars ye stole f’om me—that’s what I mean,” old Arad
declared. “Th’ money ye stoled f’om my beury droor. I gotter warrant
right here fur ye, ’n’ this officer ter serve it!”
CHAPTER XXVI
CALEB WETHERBEE OBSTRUCTS THE COURSE
OF THE LAW

Brandon was fairly paralyzed by Uncle Arad’s announcement. He


had realized that the old man was sorely disappointed at his inability
to keep him on the farm. He had not, however, believed he would
follow him clear to New York, and hatch up such a scheme as this to
get him again in his power.
“You old scoundrel!” he exclaimed, too enraged for the moment to
remember that he was speaking to a man whose age, if not his
character, should command his respect.
“Hush, Don,” commanded Adoniram Pepper admonishingly. “It will
not better matters to vituperate. Mr. Tarr,” he added, turning to the
farmer, “do you realize what a serious charge you have made
against your nephew?”
“I reckon I do,” Arad declared with vigor. “I got it all down here on er
warrant—Squire Holt made it aout hisself. I’m er-goin’ ter hev that
boy arrested for burglarizing me. Now you go erhead, Mr. Officer, an’
arrest him.”
“Wait a moment,” and Adoniram stepped quickly in front of Don
before the foxy looking man could lay his hand upon the boy’s
shoulder.
“Let me see that warrant?” he said.
The officer passed the paper over with a flourish, and Adoniram
examined it closely.
“Why,” he exclaimed, shortly, “this is returnable to the Rhode Island
courts.”
“Of course it is,” snarled old Arad.
“But do you propose taking the boy back to Rhode Island?”
“Yes, I do.”
“But can’t this be settled here, officer?” asked Adoniram nervously,
knowing that any such delay as this would ruin their plans for an
early start after the Silver Swan.
“No, sir; the robbery was committed in Rhode Island—it must be
tried there,” replied the officer, with a crafty smile.
Adoniram handed the warrant back in utter bewilderment; but at that
juncture the door opened again, and Caleb Wetherbee himself
stumped in.
“Hey! what’s this?” the old seaman demanded, seeing instantly that
something was up.
Old Arad tried to shrink out of sight behind the officer’s back as he
viewed Caleb’s fear inspiring proportions.
“This is my dear Uncle Arad, Caleb,” Brandon hastened to say, “and
he has come all the way from Rhode Island to arrest me and take
me back.”
“For what?” cried Caleb, aghast.
“For robbing him; so he says. Isn’t he kind?”
Brandon was fairly furious, but he trusted in the old seaman to get
him out of his relative’s clutches.
“Robbing him!”
Caleb’s face grew red with rage.
“What d’ye mean, ye old scamp?”
“He hez robbed me,” Arad shrieked.
“See here,” Caleb said coolly, “this looks to me like petty
persecution, don’t it to you, ’Doniram? I reckon the courts would see
it that way, too.”
“The courts’ll send that reskil ter the State reform school—that’s
what they’ll do,” Arad declared.
“So it’s locking him up you’re after, eh?” returned Caleb. “Now,
Brandon, don’t you worry about this. We kin have it fixed up in no
time.”
“But the boy’s got to be taken to Rhode Island,” exclaimed Adoniram.
“It will be a matter of weeks.”
“Weeks?” roared Caleb. “Why, the steamer sails Tuesday. He can’t
go.”
“I guess, mister, that you won’t have much to do with it,” remarked
the man with the warrant officiously. “This warrant is returnable to the
Rhode Island courts, and to Rhode Island he must go. If the boy had
wanted to go on a voyage he shouldn’t have stolen the money.”
Caleb actually roared at this and shook his huge fist in the fellow’s
face. Adoniram hastened to keep the peace.
“How do we know you are an officer?” he demanded sternly. “This is
a most atrocious action on Mr. Tarr’s part, and for all we know you
may be party to it.”
The officer smiled slily, and throwing back his coat showed his
badge.
“I’m a dep’ty sheriff an’ don’t you fear,” he said. “The boy must come
along.”
But as he reached out to clutch Don, the big sailor seized the youth
and whirled him in behind him, placing himself between the officer
and his prisoner.
“Don’t be too fast,” he said.
“Do you dare resist arrest?” the officer demanded angrily.
“Nobody’s resisted you, yet.”
His huge bulk, however, barred all approach to Don, who was now
between all the others and the outer door.
“If you arrest this boy you’ll seriously inconvenience our plans, an’
we’ll make you sweat for it, now I tell ye.”
“I don’t care; I’m er—goin’ ter hev him took up!” shrieked old Arad, to
whom all this delay was agonizing.
“You shut that trap of yours!” roared Caleb, turning upon the old man
in a fury. “Don’t ye dare open it ag’in w’ile ye’re here, or there’ll be an
assault case in court, too.”
Old Arad dodged back out of range of the sailor’s brawny fist with
great celerity.
“Do——don’t ye let him tetch me, officer,” he implored, jerking his
bandanna from the pocket of his shiny old black coat, and wiping his
face nervously.
With the handkerchief came forth a letter which fell at Mr. Pepper’s
feet; but for the moment nobody but the merchant himself saw it.
Brandon, who was directly behind the seaman, leaned forward and
whispered something in Caleb’s ear. The old seaman’s face lit up in
an instant, and he changed his position so that his burly form
completely blocked the doorway leading into the outer office.
“So you won’t settle this thing out o’ court, eh?” he demanded.
The officer shook his head.
“It’s gone too far,” he said.
“It has, hey?” Caleb exclaimed in wrath. “Well, so’ve you gone too
far.” Then he exclaimed, turning to Don: “Leg it, lad! We’ll outwit the
landlubber yet.”
“Hi! stop him! stop him!” shrieked Uncle Arad, for at the instant Caleb
had spoken, Don had darted back to the street door and thrown it
open.
“Good by, Uncle Arad!” the captain’s son cried mockingly. “I’ll see
you when I’ve returned from the West Indies.”
He was out in a moment, and the door slammed behind him.
The deputy sheriff sprang forward to follow, but Caleb managed to
get his wooden leg in the way, and the officer measured his length
on the office floor, while Uncle Arad, fairly wild with rage, danced up
and down, and shrieked for the police.
CHAPTER XXVII
WHEREIN BRANDON TARR CONCEALS
HIMSELF

The doughty deputy sheriff was on his feet in an instant, and with a
wrathy glance at Caleb, dashed out of the office after the fleeing
Brandon. If he did not make the arrest he would fail to get his money,
and he did not propose to lose that.
But Uncle Arad could not get to the door without passing Caleb and
he hardly dared do that. Just then the big seaman looked in no mood
to be tampered with. The farmer, however, did sputter out something
about having the law on everybody in general.
“Bring on all the law you want to, you old scarecrow,” responded
Caleb, vigorously mopping his face. “I reckon we kin take care of it.
What ye got there, Adoniram?”
Mr. Pepper had picked up the letter which had fallen from old Arad’s
pocket, and was looking at the superscription in a puzzled manner.
Arad caught sight of the epistle as quickly as did Caleb.
“That’s mine! give it here!” he cried, making a snatch at the paper.
But Adoniram held it out of his reach.
“I don’t see how you make that out, Mr. Tarr,” he said quietly. “This
letter is not addressed to you. It is in your handwriting, Caleb, and is
addressed to ‘Master Brandon Tarr, Chopmist, Rhode Island.’”
“Oh, you swab!” exclaimed the old tar, with a withering glance of
contempt at old Arad, as he seized the letter. “This ’ere’s what I
wrote the boy w’en I was in the hospital—w’ich same he never got.
Now, how came you by it? You old land shark!”

You might also like