Functional Data Structures in R: Advanced Statistical Programming in R Thomas Mailund instant download
Functional Data Structures in R: Advanced Statistical Programming in R Thomas Mailund instant download
https://textbookfull.com/product/functional-data-structures-in-r-
advanced-statistical-programming-in-r-thomas-mailund/
https://textbookfull.com/product/functional-data-structures-in-r-
advanced-statistical-programming-in-r-mailund/
https://textbookfull.com/product/functional-programming-in-r-
advanced-statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/domain-specific-languages-in-r-
advanced-statistical-programming-1st-edition-thomas-mailund/
https://textbookfull.com/product/domain-specific-languages-in-r-
advanced-statistical-programming-1st-edition-thomas-mailund-2/
Metaprogramming in R: Advanced Statistical Programming
for Data Science, Analysis and Finance 1st Edition
Thomas Mailund
https://textbookfull.com/product/metaprogramming-in-r-advanced-
statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/advanced-object-oriented-
programming-in-r-statistical-programming-for-data-science-
analysis-and-finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/beginning-data-science-in-r-
data-analysis-visualization-and-modelling-for-the-data-
scientist-1st-edition-thomas-mailund/
https://textbookfull.com/product/pointers-in-c-programming-a-
modern-approach-to-memory-management-recursive-data-structures-
strings-and-arrays-thomas-mailund/
https://textbookfull.com/product/advanced-r-statistical-
programming-and-data-models-analysis-machine-learning-and-
visualization-1st-edition-matt-wiley/
Functional Data
Structures in R
Advanced Statistical Programming in R
—
Thomas Mailund
Functional Data
Structures in R
Advanced Statistical
Programming in R
Thomas Mailund
Functional Data Structures in R: Advanced Statistical
Programming in R
Thomas Mailund
Aarhus N, Denmark
Chapter 1: Introduction������������������������������������������������������������������������1
iii
Table of Contents
Chapter 5: Heaps������������������������������������������������������������������������������135
Leftist Heaps�����������������������������������������������������������������������������������������������������140
Binomial Heaps�������������������������������������������������������������������������������������������������144
Splay Heaps������������������������������������������������������������������������������������������������������157
Plotting Heaps���������������������������������������������������������������������������������������������������178
Heaps and Sorting���������������������������������������������������������������������������������������������183
iv
Table of Contents
Conclusions��������������������������������������������������������������������������������������247
A
cknowledgements������������������������������������������������������������������������������������������248
Bibliography�������������������������������������������������������������������������������������249
Index�������������������������������������������������������������������������������������������������251
v
About the Author
Thomas Mailund is an associate professor in bioinformatics at Aarhus
University, Denmark. He has a background in math and computer science.
For the last decade, his main focus has been on genetics and evolutionary
studies, particularly comparative genomics, speciation, and gene flow
between emerging species. He has published Beginning Data Science in R,
Functional Programming in R, and Metaprogramming in R with Apress, as
well as other books.
vii
About the Technical Reviewer
Karthik Ramasubramanian works for one
of the largest and fastest-growing technology
unicorns in India, Hike Messenger, where
he brings the best of business analytics
and data science experience to his role. In
his seven years of research and industry
experience, he has worked on cross-industry
data science problems in retail, e-commerce,
and technology, developing and prototyping
data-driven solutions. In his previous role at Snapdeal, one of the largest
e-commerce retailers in India, he was leading core statistical modeling
initiatives for customer growth and pricing analytics. Prior to Snapdeal,
he was part of the central database team, managing the data warehouses
for global business applications of Reckitt Benckiser (RB). He has vast
experience working with scalable machine learning solutions for industry,
including sophisticated graph network and self-learning neural networks.
He has a master’s degree in theoretical computer science from PSG College
of Technology, Anna University, and is a certified big data professional. He
is passionate about teaching and mentoring future data scientists through
different online and public forums. He enjoys writing poems in his leisure
time and is an avid traveler.
ix
Introduction
This book gives an introduction to functional data structures. Many
traditional data structures rely on the structures being mutable. We can
update search trees, change links in linked lists, and rearrange values in a
vector. In functional languages, and as a general rule in the R programming
language, data is not mutable. You cannot alter existing data. The
techniques used to modify data structures to give us efficient building
blocks for algorithmic programming cannot be used.
There are workarounds for this. R is not a pure functional language,
and we can change variable-value bindings by modifying environments.
We can exploit this to emulate pointers and implement traditional
data structures this way; or we can abandon pure R programming and
implement data structures in C/C++ with some wrapper code so we can
use them in our R programs. Both solutions allow us to use traditional data
structures, but the former gives us very untraditional R code, and the latter
has no use for those not familiar with other languages than R.
The good news, though, is that we don’t have to reject R when
implementing data structures if we are willing to abandon the traditional
data structures instead. There are data structures that we can manipulate
by building new versions of them rather than modifying them. These data
structures, so-called functional data structures, are different from the
traditional data structures you might know, but they are worth knowing if
you plan to do serious algorithmic programming in a functional language
such as R.
There are not necessarily drop-in replacements for all the data
structures you are used to, at least not with the same runtime performance
for their operations, but there are likely to be implementations for most
xi
Introduction
abstract data structures you regularly use. In cases where you might have
to lose a bit of efficiency by using a functional data structures instead of a
traditional one, however, you have to consider whether the extra speed is
worth the extra time you have to spend implementing a data structure in
exotic R or in an entirely different language.
There is always a trade-off when it comes to speed. How much
programming time is a speed-up worth? If you are programming in R,
chances are you value programmer-time over computer-time. R is a high-
level language and relatively slow compared to most other languages.
There is a price to providing higher levels of expressiveness. You accept
this when you choose to work with R. You might have to make the same
choice when it comes to selecting a functional data structure over a
traditional one, or you might conclude that you really do need the extra
speed and choose to spend more time programming to save time when
doing an analysis. Only you can make the right choice based on your
situation. You need to find out the available choices to enable you to work
data structures when you cannot modify them.
xii
CHAPTER 1
Introduction
This book gives an introduction to functional data structures. Many
traditional data structures rely on the structures being mutable. We
can update search trees, change links in linked lists, and rearrange
values in a vector. In functional languages, and as a general rule in the R
programming language, data is not mutable. You cannot alter existing data.
The techniques used to modify data structures to give us efficient building
blocks for algorithmic programming cannot be used.
There are workarounds for this. R is not a pure functional language,
and we can change variable-value bindings by modifying environments.
We can exploit this to emulate pointers and implement traditional
data structures this way; or we can abandon pure R programming and
implement data structures in C/C++ with some wrapper code so we can
use them in our R programs. Both solutions allow us to use traditional data
structures, but the former gives us very untraditional R code, and the latter
has no use for those not familiar with other languages than R.
The good news, however, is that we don’t have to reject R when
implementing data structures if we are willing to abandon the traditional
data structures instead. There are data structures we can manipulate by
building new versions of them rather than modifying them. These data
structures, so-called functional data structures, are different from the
traditional data structures you might know, but they are worth knowing if
you plan to do serious algorithmic programming in a functional language
such as R.
There are not necessarily drop-in replacements for all the data
structures you are used to, at least not with the same runtime performance
for their operations—but there are likely to be implementations for most
abstract data structures you regularly use. In cases where you might have
to lose a bit of efficiency by using a functional data structure instead of a
traditional one, you have to consider whether the extra speed is worth the
extra time you have to spend implementing a data structure in exotic R or
in an entirely different language.
There is always a trade-off when it comes to speed. How much
programming time is a speed-up worth? If you are programming in R,
the chances are that you value programmer time over computer time. R
is a high-level language that is relatively slow compared to most other
languages. There is a price to providing higher levels of expressiveness.
You accept this when you choose to work with R. You might have to make
the same choice when it comes to selecting a functional data structure
over a traditional one, or you might conclude that you really do need the
extra speed and choose to spend more time programming to save time
when doing an analysis. Only you can make the right choice based on your
situation. You need to find out the available choices to enable you to work
data structures when you cannot modify them.
2
CHAPTER 2
Abstract Data
Structures
Before we get started with the actual data structures, we need to get
some terminologies and notations in place. We need to agree on what an
abstract data structure is—in contrast to a concrete one—and we need to
agree on how to reason with runtime complexity in an abstract way.
If you are at all familiar with algorithms and data structures, you can
skim quickly through this chapter. There won’t be any theory you are not
already familiar with. Do at least skim through it, though, just to make sure
we agree on the notation I will use in the remainder of the book.
If you are not familiar with the material in this chapter, I urge you to
find a text book on algorithms and read it. The material I cover in this
chapter should suffice for the theory we will need in this book, but there
is a lot more to data structures and complexity than I can possibly cover
in a single chapter. Most good textbooks on algorithms will teach you a lot
more, so if this book is of interest, you should not find any difficulties in
continuing your studies.
Structure on Data
As the name implies, data structures have something to do with structured
data. By data, we can just think of elements from some arbitrary set. There
might be some more structure to the data than the individual data points,
and when there is we keep that in mind and will probably want to exploit
that somehow. However, in the most general terms, we just have some
large set of data points.
So, a simple example of working with data would be imagining we
have this set of possible values—say, all possible names of students at a
university—and I am interested in a subset—for example, the students
that are taking one of my classes. A class would be a subset of students,
and I could represent it as the subset of student names. When I get an
email from a student, I might be interested in figuring out if it is from one
of my students, and in that case, in which class. So, already we have some
structure on the data. Different classes are different subsets of student
names. We also have an operation we would like to be able to perform on
these classes: checking membership.
There might be some inherent structure to the data we work with, which
could be properties such as lexicographical orders on names—it enables us to
sort student names, for example. Other structure we add on top of this. We add
structure by defining classes as subsets of student names. There is even a third
level of structure: how we represent the classes on our computer.
The first level of structure—inherent in the data we work with—is not
something we have much control over. We might be able to exploit it in
various ways, but otherwise, it is just there. When it comes to designing
algorithms and data structures, this structure is often simple information;
if there is order in our data, we can sort it, for example. Different
algorithms and different data structures make various assumptions about
the underlying data, but most general algorithms and data structures make
few assumptions. When I make assumptions in this book, I will make those
assumptions explicit.
4
Chapter 2 Abstract Data Structures
5
Chapter 2 Abstract Data Structures
1
I f you are unfamiliar with generic functions and the S3 system, you can check out
my book Advanced Object-Oriented Programming in R book (Apress, 2017), where
I explain all this.
6
Chapter 2 Abstract Data Structures
s <- empty_list_set()
member(s, 1)
## [1] FALSE
s <- insert(s, 1)
member(s, 1)
## [1] TRUE
7
Chapter 2 Abstract Data Structures
The reason for this is simple: our functions can’t have side effects. If a
“pop” function takes a stack as an argument, it cannot modify this stack. It
can give you the top element of the stack, and it can give you a new stack
where the top element is removed, but it cannot give you the top element
and then modify the stack as a side effect. Whenever we want to modify
a data structure, what we have to do in a functional language, is to create
a new structure instead. And we need to return this new structure to the
caller. Instead of wrapping query answers and new (or “modified”) data
structures in lists so we can return multiple values, it is much easier to
keep the two operations separate.
Another rule of thumb for interfaces that I will stick to in this book,
with one exception, is that I will always have my functions take the data
structure as the first argument. This isn’t something absolutely necessary,
but it fits the convention for generic functions, so it makes it easier to work
with abstract interfaces, and even when a function is not abstract—when
I need some helper functions—remembering that the first argument is
always the data structure is easier. The one exception to this rule is the
construction of linked lists, where tradition is to have a construction
function, cons, that takes an element as its first argument and a list as its
second argument and construct a new list where the element is put at the
head of the list. This construction is too much of a tradition for me to mess
with, and I won’t write a generic function of it, so it doesn’t come into
conflict with how we handle polymorphism.
Other than that, there isn’t much more language mechanics to creating
abstract data structures. All operations we define on an abstract data
structure have some intended semantics to them, but we cannot enforce
this through the language; we just have to make sure that the operations
we implement actually do what they are supposed to do.
8
Chapter 2 Abstract Data Structures
9
Chapter 2 Abstract Data Structures
We can construct linked lists in R using R’s built-in list data structure.
That structure is not a linked list; it is a fixed-size collection of elements
that are possibly named. We exploit named elements to build pointers. We
can implement the CONS construction like this:
We just construct a list with two elements, head and tail. These will
be references to other objects—head to the element we store in the list, and
tail to the rest of the list—so we are in effect using them as pointers. We
then add a class to the list to make linked lists work as an implementation
of an abstract data structure.
Using classes and generic functions to implement polymorphic
abstract data structures leads us to the second issue we need to deal with
in R. We need to be able to represent empty lists. The natural choice for
an empty list would be NULL, which represents “nothing” for the built-in
list objects, but we can’t get polymorphism to work with NULL. We can’t
give NULL a class. We could, of course, still work with NULL as the empty list
and just have classes for non-empty lists, but this clashes with our desire
to have the empty data structures being the one point where we decide
concrete data structures instead of just accessing them through an abstract
interface. If we didn’t give empty data structures a type, we would need
to use concrete update functions instead. That could make switching
between different implementations cumbersome. We really do want to
have empty data structures with classes.
The trick is to use a sentinel object to represent empty structures.
Sentinel objects have the same structure as non-empty data structure
objects—which has the added benefit of making some implementations
easier to write—but they are recognized as representing “empty.” We
construct a sentinel as we would any other object, but we remember it
10
Chapter 2 Abstract Data Structures
The is_empty function is a generic function that we will use for all data
structures.
The identical test isn’t perfect. It will consider any list element
containing NA as the last item in a list as the sentinel. Because we don’t
expect anyone to store NA in a linked list—it makes sense to have missing
data in a lot of analysis, but rarely does it make sense to store it in data
structures—it will have to do.
Using a sentinel for empty data structures can also occasionally be
useful for more than dispatching on generic functions. Sometimes, we
actually want to use sentinels as proper objects, because it simplifies certain
functions. In those cases, we can end up with associating meta-data with
“empty” sentinel objects. We will see examples of this when we implement
red-black search trees. If we do this, then checking for emptiness
using identical will not work. If we modify a sentinel to change meta-
information, it will no longer be identical to the reference empty object. In
those cases, we will use other approaches to testing for emptiness.
11
Chapter 2 Abstract Data Structures
Because of this, we often consider the time efficiency part of the interface
of a data structure—if not part of the abstract data structure, we very much
care about it when we have to pick concrete implementations of data
structures for our algorithms.
When it comes to algorithmic performance, the end goal is always to
reduce wall time—the actual time we have to wait for a program to finish.
But this depends on many factors that cannot necessarily know about
when we design our algorithms. The computer the code will run on might
not be available to us when we develop our software, and both its memory
and CPU capabilities are likely to affect the running time significantly. The
running time is also likely to depend intimately on the data we will run the
algorithm on. If we want to know exactly how long it will take to analyze a
particular set of data, we have to run the algorithm on this data. Once we
have done this, we know exactly how long it took to analyze the data, but
by then it is too late to explore different solutions to do the analysis faster.
Because we cannot practically evaluate the efficiency of our algorithms
and data structures by measuring the running time on the actual data we
want to analyze, we use different techniques to judge the quality of various
possible solutions to our problems.
One such technique is the use of asymptotic complexity, also known as
big-O notation. Simply put, we abstract away some details of the running
time of different algorithms or data structure operations and classify their
runtime complexity according to upper bounds known up to a constant.
First, we reduce our data to its size. We might have a set with n
elements, or a string of length n. Although our data structures and
algorithms might use very different actual wall time to work on different
data of the same size, we care only about the number n and not the details
of the data. Of course, data of the same size is not all equal, so when
we reduce all our information about it to a single size, we have to be a
little careful about what we mean when we talk about the algorithmic
complexity of a problem. Here, we usually use one of two approaches: we
speak of the worst-case or the average/expected complexity. The worst-case
12
Chapter 2 Abstract Data Structures
13
Chapter 2 Abstract Data Structures
runs in any big-O complexity that is an upper bound for the actual
runtime complexity. We want to get this upper bound as exact as we can,
to properly evaluate different choices of algorithms, but if we have upper
and lower bounds for various algorithms, we can still compare them.
Even if the bounds are not tight, if we can see that the upper bound of one
algorithm is better than the lower bound of another, we can reason about
the asymptotic running time of solutions based on the two.
To see the asymptotic reasoning in action, consider the set
implementation we wrote earlier:
14
Chapter 2 Abstract Data Structures
15
Chapter 2 Abstract Data Structures
16
Chapter 2 Abstract Data Structures
library(tibble)
library(microbenchmark)
17
Chapter 2 Abstract Data Structures
18
Chapter 2 Abstract Data Structures
library(ggplot2)
ggplot(performance, aes(x = n, y = time, colour = algo)) +
geom_jitter() +
geom_smooth(method = "loess",
span = 2, se = FALSE) +
scale_colour_grey("Data structure", end = 0.5) +
xlab(quote(n)) + ylab("Time (sec)") + theme_minimal()
19
Random documents with unrelated
content Scribd suggests to you:
and do you think you could get us some little thing now?'
'Here?' said he, with his face lighting up with pleasure: were
those three to have supper all by themselves?
'Oh yes,' said she, in her friendly way. 'I am not sure that my
mother would like me to stay at the inn for supper; but this is our
own place; and the table laid; and Maggie and I would rather be
here, I am sure. And you—are you not hungry too—after so long a
time—I am sure you want something besides raisins and shortbread.
But if it will be any trouble—
'Trouble or no trouble,' said he quickly, 'has nothing to do wi't.
Here, Maggie, lass, clear the end of the table; and we'll soon get
some supper for ye.'
And away he went to the inn, summoning the lasses there, and
driving and hurrying them until they had arranged upon a large tray
a very presentable supper—some cold beef, and ham, and cheese,
and bread, and ale; and when the fair-haired Nelly was ready to
start forth with this burden, he lit a candle and walked before her
through the darkness, lest she should miss her footing. And very
demure was Nelly when she placed this supper on the table; there
was not even a look for the smart young keeper; and when Meenie
said to her—
'I hear, Nelly, you had great goings-on on Monday night'—she
only answered—'Oh yes, miss, there was that'—and could not be
drawn into conversation, but left the moment she had everything
arranged.
But curiously enough, when the two girls had taken their seats
at this little cross table, Ronald remained standing—just behind
them, indeed, as if he were a waiter. And would Miss Douglas have
this? and would Miss Douglas have that? he suggested—mostly to
cloak his shamefacedness; for indeed that first wild assumption that
they were all to have supper together was banished now as an
impertinence. He would wait on them, and gladly; but—but his own
supper would come after.
'And what will you have yourself, Ronald?' Meenie asked.
'Oh,' said he, 'that will do by and by. I am not so hungry as
you.'
'Did you have so much of the shortbread?' said she, laughing.
He went and stirred up the peats—and the red glow sent a
genial warmth across towards them.
'Come, Ronald,' said the little Maggie, 'and have some supper.'
'There is no hurry,' he said evasively. 'I think I will go outside
and have a pipe now; and get something by and by.'
'I am sure,' said Meenie saucily, 'that it is no compliment to us
that you would rather go away and smoke. See, now, if we cannot
tempt you.'
And therewith, with her own pretty fingers, she made ready his
place at the table; and put the knife and fork properly beside the
plate; and helped him to a slice of beef and a slice of ham; and
poured some ale into his tumbler. Not only that, but she made a little
movement of arranging her dress which was so obviously an
invitation that he should there and then take a place by her, that it
was not in mortal man to resist; though, indeed, after sitting down,
he seemed to devote all his attention to looking after his
companions. And very soon any small embarrassment was entirely
gone; Meenie was in an unusually gay and merry mood—for she was
pleased that her party had been so obviously a success, and all her
responsibilities over. And this vivacity gave a new beauty to her face;
her eyes seemed more kind than ever; when she laughed, it was a
sweet low laugh, like the cooing of pigeons on a summer afternoon.
'And what are you thinking of, Maggie?' she said, suddenly
turning to the little girl, who had grown rather silent amid this
talking and joking.
'I was wishing this could go on for ever,' was the simple answer.
'What? A perpetual supper? Oh, you greedy girl! Why, you must
be looking forward to the Scandinavian heaven——'
'No, it's to be with Ronald and you, Meenie dear—just like now
—for you seem to be able to keep everybody happy.'
Miss Douglas did blush a little at this; but it was an honest
compliment, and it was soon forgotten. And then, when they had
finished supper, she said—
'Ronald, do you know that I have never played an
accompaniment to one of your songs? Would you not like to hear
how it sounds?
'But—but I'm not used to it—I should be putting you wrong——'
'No, no; I'm sure we will manage. Come along,' she said briskly.
'There is that one I heard you sing the other day—I heard you,
though you did not see me—"Gae bring to me a pint o' wine, and fill
it in a silver tassie; that I may drink, before I go, a service to my
bonnie lassie"—and very proud she was, I suppose. Well, now, we
will try that one.'
So they went to the other end of the barn, where the piano
was; and there was a good deal of singing there, and laughing and
joking—among this little party of three. And Meenie sang too—on
condition (woman-like) that Ronald would light his pipe. Little
Maggie scarcely knew which to admire the more—this beautiful and
graceful young lady, who was so complaisant and friendly and kind,
or her own brother, who was so handsome and manly and modest,
and yet could do everything in the world. Nor could there have been
any sinister doubt in that wish of hers that these three should always
be together as they were then; how was she to know that this was
the last evening on which Meenie Douglas and Ronald were to meet
on these all too friendly terms?
CHAPTER XI.
A REVELATION.
Early the next morning, when as yet the sunrise was still widening
up and over the loch, and the faint tinge of red had not quite left the
higher slopes of Clebrig, Ronald had already finished his breakfast,
and was in his own small room, smoking the customary pipe, and
idly—and with some curious kind of whimsical amusement in his
brain—turning over the loose sheets of scribbled verses. And that
was a very ethereal and imaginary Meenie he found there—a Meenie
of lonely hillside wanderings—a Meenie of daydreams and visions:
not the actual, light-hearted, shrewd-headed Meenie of the evening
before, who was so merry after the children had gone, and so
content with the little supper-party of three, and would have him
smoke his pipe without regard to her pretty silk dress. This Meenie
on paper was rather a wistful, visionary, distant creature; whereas
the Meenie of the previous evening was altogether good-humoured
and laughing, with the quaintest mother-ways in the management of
the children, and always a light of kindness shining in her clear
Highland eyes. He would have to write something to portray Meenie
(to himself) in this more friendly and actual character. He could do it
easily enough, he knew. There never was any lack of rhymes when
Meenie was the occasion. At other things he had to labour—
frequently, indeed, until, reflecting that this was not his business, he
would fling the scrawl into the fire, and drive it into the peats with
his heel, and go away with much content. But when Meenie was in
his head, everything came readily enough; all the world around
seemed full of beautiful things to compare with her; the birds were
singing of her; the mountains were there to guard her; the burn, as
it whispered through the rushes, or danced over the open bed of
pebbles, had but the one continual murmur of Meenie's name.
Verses? he could have written them by the score—and laughed at
them, and burned them, too.
Suddenly the little Maggie appeared.
'Ronald,' she said, 'the Doctor's come home.'
'What—at this time in the morning?' he said turning to her.
'Yes, I am sure; for I can see the dog-cart at the door of the
inn.'
'Well now,' said he, hastily snatching up his cap, 'that is a stroke
of luck—if he will come with us. I will go and meet him.'
But he need not have hurried so much; the dog-cart was still at
the door of the inn when he went out; and indeed remained there as
he made his way along the road. The Doctor, who was a most
sociable person, had stopped for a moment to hear the news; but
Mr. Murray happened to be there, and so the chat was a protracted
one. In the meantime Ronald's long swinging stride soon brought
him into their neighbourhood.
'Good morning, Doctor!' he cried.
'Good morning, Ronald,' said the other, turning round. He was a
big man, somewhat corpulent, with an honest, wholesome, ruddy
face, soft brown eyes, and an expressive mouth, that could temper
his very apparent good-nature with a little mild sarcasm.
'You've come back in the nick of time,' the keeper said—for well
he knew the Doctor's keen love of a gun. 'I'm thinking of driving
some of the far tops the day, to thin down the hares a bit; and I'm
sure ye'd be glad to lend us a hand.'
'Man, I was going home to my bed, to tell ye the truth,' said the
Doctor; 'it's very little sleep I've had the last ten days.'
'What is the use of that?' said Ronald, 'there's aye plenty o' time
for sleep in the winter.'
And then the heavy-framed occupant of the dog-cart glanced up
at the far-reaching heights of Clebrig, and there was a grim smile on
his mouth.
'It's all very well,' said he, 'for herring-stomached young fellows
like you to face a hill like that; but I've got weight to carry, man; and
—
'Come, come, Doctor; it's not the first time you've been on
Clebrig,' Ronald said—he could see that Meenie's father wanted to
be persuaded. 'Besides, we'll no try the highest tops up there—
there's been too much snow. And I'll tell ye how we'll make it easy
for ye; we'll row ye down the loch and begin at the other end and
work home—there, it's a fair offer.'
It was an offer, at all events, that the big doctor could not
withstand.
'Well, well,' said he, 'I'll just drive the dog-cart along and see
how they are at home; and then if the wife lets me out o' her
clutches, I'll come down to the loch side as fast as I can.'
Ronald turned to one of the stable-lads (all of whom were
transformed into beaters on this occasion).
'Jimmy, just run over to the house and fetch my gun; and bid
Maggie put twenty cartridges—number 4, she knows where they are
—into the bag; and then ye can take the gun and the cartridge-bag
down to the boat—and be giving her a bale-out till I come along. I'm
going to the farm now, to get two more lads if I can; tell the Doctor
I'll no be long after him, if he gets down to the loch first.'
Some quarter of an hour thereafter they set forth; and a rough
pull it was down the loch, for the wind was blowing hard, and the
waves were coming broadside on. Those who were at the oars had
decidedly the best of it, for it was bitterly cold; but even the others
did not seem to mind much—they were chiefly occupied in scanning
the sky-line of the hills (a habit that one naturally falls into in a deer
country), while Ronald and the Doctor, seated in the stern, were
mostly concerned about keeping their guns dry. In due course of
time they landed, made their way through a wood of young birch-
trees, followed the channel of a burn for a space, and by and by
began to reach the upper slopes, where the plans for the first drive
were carefully drawn out and explained.
Now it is unnecessary to enter into details of the day's
achievements, for they were neither exciting nor difficult nor daring.
It was clearly a case of shooting for the pot; although Ronald, in his
capacity of keeper, was anxious to have the hares thinned down,
knowing well enough that the over-multiplying of them was as
certain to bring in disease as the overstocking of a mountain farm
with sheep. But it may be said that the sport, such as it was, was
done in a workmanlike manner. In Ronald's case, each cartridge
meant a hare—and no praise to him, for it was his business. As for
the Doctor, he was not only an excellent shot, but he exercised a
wise and humane discretion as well. Nothing would induce him to
fire at long range on the off-chance of hitting; and this is all the
more laudable in the shooting of mountain hares, for these, when
wounded, will frequently dodge into a hole among the rocks, like a
rabbit, baffling dogs and men, and dying a miserable death.
Moreover, there was no need to take risky shots. The two guns were
posted behind a stone or small hillock—lying at full length on the
ground, only their brown-capped heads and the long barrels being
visible. Then the faint cries in the distance became somewhat louder
—with sticks rattled on rocks, and stones flung here and there;
presently, on the sky-line of the plateau, a small object appeared,
sitting upright and dark against the sky; then it came shambling
leisurely along—becoming bigger and bigger and whiter and whiter
every moment, until at length it showed itself almost like a cat, but
not running stealthily like a cat, rather hopping forward on its
ungainly high haunches; and then again it would stop and sit up, its
ears thrown back, its eyes not looking at anything in front of it, its
snow-white body, with here and there a touch of bluish-brown,
offering a tempting target for a pea-rifle. But by this time, of course,
numerous others had come hopping over the sky-line; and now as
the loud yells and shouts and striking of stones were close at hand,
there was more swift running instead of hobbling and pausing
among the white frightened creatures; and as they cared for nothing
in front (in fact a driven hare cannot see anything that is right ahead
of it, and will run against your boots if you happen to be standing in
the way), but sped noiselessly across the withered grass and hard
clumps of heather—bang! went the first barrel, and then another
and another, as quick as fingers could unload and reload, until here,
there, and everywhere—but always within a certain radius from the
respective posts—a white object lay on the hard and wintry ground.
The beaters came up to gather them together; the two guns had
risen from their cold quarters; there were found to be thirteen hares
all told—a quite sufficient number for this part—and not one had
crawled or hobbled away wounded.
But we will now descend for a time from these bleak altitudes
and return to the little hamlet—which seemed to lie there snugly
enough and sheltered in the hollow, though the wind was hard on
the dark and driven loch. Some hour or so after the shooters and
beaters had left, Meenie Douglas came along to Ronald's cottage,
and, of course, found Maggie the sole occupant, as she had
expected. She was very bright and cheerful and friendly, and spoke
warmly of Ronald's kindness in giving her father a day's shooting.
'My mother was a little angry,' she said, laughing, 'that he
should go away just the first thing after coming home; but you
know, Maggie, he is so fond of shooting; and it is not always he can
get a day, especially at this time of the year: and I am very glad he
has gone; for you know there are very few who have to work so
hard.'
'I wish they may come upon a stag,' said the little Maggie—with
reckless and irresponsible generosity.
'Do you know, Maggie,' said the elder young lady, with a shrewd
smile on her face, 'I am not sure that my mother likes the people
about here to be so kind; she is always expecting my father to get a
better post—but I know he is not likely to get one that will suit him
as well with the fishing and shooting. There is the Mudal—the
gentlemen at the lodge let him have that all the spring through; and
when the loch is not let, he can always have a day by writing to Mr.
Crawford; and here is Ronald, when the hinds have to be shot at
Christmas, and so on. And if the American gentleman takes the
shooting as well as the loch, surely he will ask my father to go with
him a day or two on the hill; it is a lonely thing shooting by one's
self. Well now, Maggie, did you put the curtains up again in Ronald's
room?'
'Yes, I did,' was the answer, 'and he did not tear them down this
time, for I told him you showed me how to hang them; but he has
tied them back so that they might just as well not be there at all.
Come and see, Meenie dear.'
She led the way into her brother's room; and there, sure
enough, the window-curtains (which were wholly unnecessary, by
the way, except from the feminine point of view, for there was
certainly not too much light coming in by the solitary window) had
been tightly looped and tied back, so that the view down the loch
should be unimpeded.
'No matter,' said Meenie; 'the window is not so bare-looking as it
used to be. And I suppose he will let them remain up now.'
'Oh yes, when he was told that you had something to do with
them,' was the simple answer.
Meenie went to the wooden mantelpiece, and put the few
things there straight, just as she would have done in her own room,
blowing the light white peat-dust off them, and arranging them in
neater order.
'I wonder, now,' she said, 'he does not get frames for these
photographs; they will be spoiled by finger marks and the dust.'
Maggie said shyly—
'That was what he said to me the other day—but not about
these—about the one you gave me of yourself. He asked to see it,
and I showed him how careful I was in wrapping it up; but he said
no—the first packman that came through I was to get a frame if he
had one, and glass too; or else that he would send it in to Inverness
to be framed. But you know, Meenie, it's not near so nice-looking—
or anything, anything like so nice-looking—as you are.'
'Nothing could be that, I am sure,' said Meenie lightly; and she
was casting her eyes about the room, to see what further
improvements she could suggest.
But Maggie had grown suddenly silent, and was standing at the
little writing-table, apparently transfixed with astonishment. It will be
remembered that when Ronald, in the morning, heard that the
Doctor was at the door of the inn, he had hurriedly hastened away
to intercept him; and that, subsequently, in order to save time, he
had sent back a lad for his gun and cartridges, while he went on to
the farm. Now it was this last arrangement that caused him to
overlook the fact that he had left his writing materials—the blotting-
pad and everything—lying exposed on the table; a piece of neglect
of which he had scarcely ever before been guilty. And as ill-luck
would have it, as Maggie was idly wandering round the room,
waiting for Meenie to make any further suggestions for the
smartening of it, what must she see lying before her, among these
papers, but a letter, boldly and conspicuously addressed?
'Well!' she exclaimed, as she took it up. 'Meenie, here is a letter
for you! why didna he send it along to you?'
'A letter for me?' Meenie said, with a little surprise. 'No! why
should Ronald write a letter to me?—I see him about every day.'
'But look!'
Meenie took the letter in her hand; and regarded the address;
and laughed.
'It is very formal,' said she. 'There is no mistake about it. "Miss
Wilhelmina Stuart Douglas"—when was I ever called that before?
And "Inver-Mudal, Sutherlandshire, N.B." He should have added
Europe, as if he was sending it from the moon. Well, it is clearly
meant for me, any way—oh, and open too——'
The next minute all the careless amusement fled from her face;
her cheeks grew very white, and a frightened, startled look sprang
to her eyes. She but caught the first few lines—
and then it was with a kind of shiver that her glance ran over the
rest of it; and her heart was beating so that she could not speak;
and there was a mist before her eyes.
'Maggie,' she managed to say at length—and she hurriedly
folded up the paper again and placed it on the table with the others
—'I should not have read it—it was not meant for me—it was not
meant that I should read it—come away, come away, Maggie.'
She took the younger girl out of the room, and herself shut the
door, firmly, although her fingers were all trembling.
'Maggie,' she said, 'you must promise never to tell any one that
you gave me that letter—that I saw it——'
'But what is the matter, Meenie?' the smaller girl said in
bewilderment, for she could see by the strange half-frightened look
of Miss Douglas's face that something serious had happened.
'Well, it is nothing—it is nothing,' she forced herself to say. 'It
will be all right. I shouldn't have read the letter—it was not meant
for me to see—but if you say nothing about it, no harm will be done.
That's all; that's all. And now I am going to see if the children are
ready that are to go by the mail-car.'
'But I will go with you, Meenie.'
Then the girl seemed to recollect herself; and she glanced
round at the interior of the cottage, and at the little girl, with an
unusual kind of look.
'No, no, not this morning, Maggie,' she said. 'You have plenty to
do. Good-bye—good-bye!' and she stooped and kissed her, and
patted her on the shoulder, and left, seeming anxious to get away
and be by herself.
Maggie remained there in considerable astonishment. What had
happened? Why should she not go to help with the children? and
why good-bye—when Meenie would be coming along the road in
less than an hour, as soon as the mail-car had left? And all about the
reading of something contained in that folded sheet of paper.
However, the little girl wisely resolved that, whatever was in that
letter, she would not seek to know it, nor would she speak of it to
any one, since Meenie seemed so anxious on that point; and so she
set about her domestic duties again—looking forward to the end of
these and the resumption of her knitting of her brother's jersey.
Well, the winter's day went by, and they had done good work on
the hill. As the dusk of the afternoon began to creep over the
heavens, they set out for the lower slopes on their way home; and
very heavily weighted the lads were with the white creatures slung
over their backs on sticks. But the dusk was not the worst part of
this descent; the wind was now driving over heavy clouds from the
north; and again and again they would be completely enveloped,
and unable to see anywhere more than a yard from their feet. In
these circumstances Ronald took the lead; the Doctor coming next,
and following, indeed, more by sound than by sight; the lads
bringing up in the wake in solitary file, with their heavy loads
thumping on their backs. It was a ghostly kind of procession; though
now and again the close veil around them would be rent in twain,
and they would have a glimpse of something afar off—perhaps a
spur of Ben Loyal, or the dark waters of Loch Meidie studded with its
small islands. Long before they had reached Inver-Mudal black night
had fallen; but now they were on easier ground; and at last the firm
footing of the road echoed to their measured tramp, as the invisible
company marched on and down to the warmth and welcome lights
of the inn.
The Doctor, feeling himself something of a truant, went on
direct to his cottage; but the others entered the inn; and as Ronald
forthwith presented Mrs. Murray with half a dozen of the hares, the
landlord was right willing to call for ale for the beaters, who had had
a hard day's work. Nor was Ronald in a hurry to get home; for he
heard that Maggie was awaiting him in the kitchen; and so he and
Mr. Murray had a pipe and a chat together, as was their custom.
Then he sent for his sister.
'Well, Maggie, lass,' said he, as they set out through the dark,
'did you see all the bairns safely off this morning?'
'No, Ronald,' she said, 'Meenie did not seem to want me; so I
stayed at home.'
'And did you find Harry sufficient company for ye? But I suppose
Miss Douglas came and stayed with ye for a while.'
'No, Ronald,' said the little girl, in a tone of some surprise; 'she
has not been near the house the whole day, since the few minutes in
the morning.'
'Oh,' said he, lightly, 'she may have been busy, now her father is
come home. And ye maun try and get on wi' your lessons as well as
ye can, lass, without bothering Miss Douglas too much; she canna
always spend so much time with ye.'
The little girl was silent. She was thinking of that strange
occurrence in the morning of which she was not to speak; and in a
vague kind of way she could not but associate that with Meenie's
absence all that day, and also with the unusual tone of her 'good-
bye.' But yet, if there were any trouble, it would speedily pass away.
Ronald would put everything right. Nobody could withstand him—
that was the first and last article of her creed. And so, when they got
home, she proceeded cheerfully enough to stir up the peats, and to
cook their joint supper in a manner really skilful for one of her years;
and she laid the cloth; and put the candles on the table; and had the
tea and everything ready. Then they sate down; and Ronald was in
very good spirits, and talked to her, and tried to amuse her. But the
little Maggie rather wistfully looked back to the brilliant evening
before, when Meenie was with them; and perhaps wondered
whether there would ever again be a supper-party as joyful and
friendly and happy as they three had been when they were all by
themselves in the big gaily-lit barn.
CHAPTER XII.
'WHEN SHADOWS FALL.'
The deershed adjoining the kennels was a gloomy place, with its
bare walls, its lack of light, and its ominous-looking crossbeams,
ropes, and pulley for hanging up the slain deer; and the morning
was dark and lowering, with a bitter wind howling along the glen,
and sometimes bringing with it a sharp smurr of sleet from the
northern hills. But these things did not seem to affect Ronald's spirits
much as he stood there, in his shirt-sleeves, and bare-headed,
sorting out the hares that were lying on the floor, and determining to
whom and to whom such and such a brace or couple of brace should
be sent. Four of the plumpest he had already selected for Mrs.
Douglas (in the vague hope that the useful present might make her
a little more placable), and he was going on with his choosing and
setting aside—sometimes lighting a pipe—sometimes singing
carelessly—
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com