Last update: Oct. 15th, 2018


For each chapter, supplementary materials break down into:
– code files,
– datasets.
The naming convention for the code files is the following: code_CLSR_chapX.R
The naming convention for the datasets is the following: nameofdataset.rds or nameofdataset.txt

The code files are designed in such a way that they follow the book’s progression. I suggest that you open the code file that corresponds to the book chapter that you are interested in and enter the code as you read to avoid retyping everything.

The code files contain extra lines, tips, and warnings. They also contain minor corrections with respect to how the code should be entered.


The above URL points to an alternate, up-to-date repository on an academic server for which I have the full access rights.

Entering pathnames on Windows

One difficulty that I had to address during the writing stage is the difference between PCs running on Windows and Macs running on Mac OS with respect to pathnames. Throughout the book, you will have to provide the path to some working files (datasets, for instance).

A pathname (also known as a path) is the location where a computer file or any other object is located. Suppose that the text file <myfile.txt> is located in a folder named <mysubfolder>, which is itself located inside another folder named <myfolder>, which is itself located at the root of your hard drive (on Mac OS, the root folder is called Macintosh HD and is simply named /, whereas on Windows, it is C:). To access the text file, you provide its full path.

On a Mac, the full path is likely to be the following:

On a PC running on Windows, the path is likely to be the following:

In the book, I have adopted the above conventions. In practice, however, due to the variety of computer configurations, this might not work for all Windows users.

If, as a Windows user, you encounter an issue, convert the single slash to a pair of backslashes whenever you have to enter a file path, like so:


To save you the trouble of switching from slashes to double backslashes manually, I have made the changes myself in the companion code files (not in the book).

On several occasions in the book, I write pathnames « the Mac way », i.e. without the Windows equivalent. I have done this for reasons of space, and also because I work on a Mac and sometimes forget that most users work with a PC. In the companion code files, I have systematically added the Windows convention.

If you think that entering pathnames is tedious, you can still use file.choose(), which will prompt R to open an interactive window from which you can select the desired file.

Forcing the root directory to appear on Mac OS

Recent versions of Mac OS X and macOS have started to hide the root folder from users (the root folder is the folder at the root of your hard drive). To make the root folder appear, follow these steps:

  • anywhere on the Desktop, enter Command+Shift+G, then type / and hit return. This will take you to root (Macintosh HD)
  • drag & drop Macintosh HD into the Finder sidebar.

You may also want to display Macintosh HD on your Desktop. In this case, open the Finder menu and choose « Preferences ». Under the « General » tab check the box next to « Hard disks ». This will show Macintosh HD.


If you have any question, if you spot a typo or an error, or if you simply want to say how much you liked the book, please drop me a line!

Errata list

Chapter 1

  • p. 2

« no corpus, however large and balanced, can ever hoped to be representative of a speaker […] » –> « can ever hope » (source : Christophe Béchet, Université de Liège, Belgium)

  • p. 4

« […] used to compile the spoken component of the British National Corpus The British National Corpus (2007). » –> duplicate (source : C. Béchet, henceforth C.B.). This is due to how LaTeX generates the bibliographical reference.

  • p. 5

« the materiality its database, or lack thereof » –> « the materiality of its database » (C.B.)

Chapter 2

  • p. 20

« each type you type age » –> « each time you type age » (C.B.)

  • p. 38

A slash is missing in the following line of code:

df <- read.table("C:/CLSRchap2/sample.df.txt", header=TRUE, sep="\t") # Windows

It should be:

df <- read.table("C:/CLSR/chap2/sample.df.txt", header=TRUE, sep="\t") # Windows
  • p. 39

(footnote) « with regards to its mode » –> « with regard to » (C.B.)

Chapter 3

  • p. 51

« until its compiler stopped adding more text materials 2015. » –> « […] stopped adding text materials in 2015. » (C.B.)

« The Bank of English The Bank of English (1980s-present) » –> « The Bank of English (1980s-present) » (C.B.) Again, this is due to the LaTeX rendering of the bibliography.

  • p. 54

« 40000 books » –> « 40,000 books » (C.B.)

  • p. 55

« the default language of the system if English » –> « […] is English » (C.B.)

  • p. 57

« Creating a plain-text, unannotated corpora » –> « Creating a plain-text, unannotated corpus » (C.B.)

  • p. 62

original code

install.packages(c("NLP", "openNLP", "stringr"))

corrected code:

install.packages("NLP", "openNLP", "stringr")

(thanks go to Christian Paga, PhD candidate at the Department of Anglophone Studies at University of Duisburg Essen, Germany, for pointing this out to me).

Also, getting openNLP to work requires rJava. Depending on your version of macOS, getting openNLP to work can be very tricky. Please take a look at this blog post.

  • p. 66

It seems that the necessary arguments for TreeTagger to understand that the text is in German are already added. (C.B.)

Chapter 5

  • p. 88

code snippets: In order to avoid encoding issues while reading in the file in R, C.B. suggests to add encoding="UTF-8" as an argument of scan.

  • p. 91

(code snippet) replacesplit withsplit.tv2 fornode, left.context, and right.context (C.B.)

Chapter 8

  • p. 154

The data table /CLSR/chap8/cont.table.rds has been modified in the CLSR folder on the Nakala repository. I have removed the row totals and the column totals.

Chapter 9

  • pp. 223-226

Thanks go to Brian Ortner for spotting the typo.

formula 9.13

c should be replaced by b

I was confused by a typo in a draft version of Gries (2013, p. 144). The original equation is 5b in Allan (1980, p. 148). On p. 224, this affects equation 9.15. Fortunately, given the very high value of cell d, the total is not much affected.


equation 9.15

The code should be:

m <- matrix(c(1633, 61502, 34877, 533690920), nrow=2, ncol=2, byrow=TRUE)
delta.W2.W1 <- (m[1,1]/(m[1,1]+m[1,2])) - (m[2,1]/(m[2,1]+m[2,2]))
delta.W1.W2 <- (m[1,1]/(m[1,1]+m[2,1])) - (m[1,2]/(m[1,2]+m[2,2]))
delta.W2.W1 - delta.W1.W2

The whole script is now:

data <- readRDS("C:\\CLSR\\chap9\\computer.NP.rds") # Windows
data <- readRDS("/CLSR/chap9/computer.NP.rds") # Mac
freq_W1 <- 63135 # frequency of computer in corpus
corp.size <- 533788932 <- character()
for (i in 1:nrow(data)){ # enter the loop
a <- data$freq_W1_W2[i] # cell a
b <- freq_W1 - a # cell b
c <- data$corp_freq_W2[i] - a # cell c
d <- (corp.size - freq_W1) - c # cell d
m <- matrix(c(a, b, c, d), nrow=2, ncol=2, byrow=TRUE) # make the 2x2 matrix <- (m[1,1]/(m[1,1]+m[1,2])) - (m[2,1]/(m[2,1]+m[2,2])) # first delta <- (m[1,1]/(m[1,1]+m[2,1])) - (m[1,2]/(m[1,2]+m[2,2])) # second delta <- - # delta difference <- round(, 4) # round <- paste(data$W2[i],, sep="\t") # append word 2 <- c(, # collect all delta differences
} # exit the loop

When you run the script, you obtain the following output:

On p. 226, the typo affects eq. 9.19. Again, because of the high value of cell d, the result is virtually unaffected.

equation 9.19

Chapter 10

  • p. 241

« This means that you will often need more than one planes » –> « This means that you will often need more than one plane » (C.B.)

  • p. 243

« PCA it takes as input » –> « PCA takes as input » (C.B.)

  • p. 252

« In this case, plotting the graph individuals with PCA » –> « In this case, plotting the graph of individuals with PCA » (C.B.)

  • p. 259

original code

data <- readRDS("/CLSR/chap10/df_extenders.rds") # Windows

corrected code

data <- readRDS("C:/CLSR/chap10/df_extenders.rds") # Windows
  • p. 285

original code

v.attr.dat <- readRDS("/CLSR/chap10/v.attr.dat.rds") # Windows

corrected code

v.attr.dat <- readRDS("C:/CLSR/chap10/v.attr.dat.rds") # Windows
  • p. 286

original code

G <-, vertices=v.attr.dat, directed="FALSE")

corrected code

G <-, vertices=v.attr.dat, directed=FALSE)
  • Section 10.7 (network graphs)

Thanks go to Stefan Th. Gries for reporting a bug, which has nothing to do with my code but comes from either R or the igraph package (I haven’t figured out which one yet). From some unknown reason, if you do not switch off R between two graphs, you may end up with some strange result (see screenshot below).

this happens when you plot figs. 10.20 and 10.21 in a row and fail to restart R in between!

R keeps the following line of code in memory no matter what, including when you enter rm(list=ls(all=TRUE)!

labels <- c("node 1", "node 2", "node 3", "node 4", "node 5", "node 6", "node 7", "node 8",
"node 9", "node 10")

As a result,  the line of code overrides the label setting of the next graph: vertex.label=v.label. The bottom line is :

  • run the code for each graph separately,
  • restart R in between.
Cite this article as: Guillaume Desagulier, "Errata," in Around the word, 18/11/2017,