aaa-sand: The sand package

Description In brief The data sets Code chunks The cursor Author(s) See Also Examples


This R package accompanies the book ‘Statistical Analysis of Network Data with R, 2nd Edition’. It contains some of the data sets used in the book (the others are in the igraphdata package). It also contains the code from the book, and some simple functions to run the code without the need for typing it in.

In brief

Type in N<enter> to run the next chunk of code, and C<x> to jump to Chapter x, where x is between 2 and 11. E.g. C6<enter> resets R and “loads” Chapter 6. P<enter> prints the next code chunk to be run (without actually running it).

The data sets

The various data sets are loaded from the code chunks in the book. The sand package contains the following data sets, each is documented in its on manual page: Ecoli, aidsblog, calldata, elist.lazega, fblog, g.bip, hc, lazega, ppi.CC, sandwichprobe, strike, v.attr.lazega.

Code chunks

Code chunks of the book are numbered by chapter and each chunk is identified the chapter number and the chunk number connected by a dot.

The reader is supposed to run the code chapter by chapter, ideally, starting from a clean, new R session. This might not be critical, but it is not always possible to unload packages in R, so it is the only way to make sure that the code works correctly.

To make it easy to step through the code, the sand package define some “commands”. Note that these are are not functions, and also q that they are meant to be used interactively, and not programatically.

The cursor

The cursor marks the point the reader is at in the book, and commands discussed below move the cursor and run the code the cursor is at.

The ‘C’ commands clear R, i.e. unload all loaded packages except for sand and its dependencies, and delete all objects from the global workspace. They also set the cursor to the first chunk of the given chapter: there are nine ‘C’ commands, from ‘C2’ to ‘C11’, one for each Chapter of the book. (Chapter 1 has no code to run.)

The command ‘N’ runs the chunk at the cursor, and steps the cursor to the next chunk. It is possible to run multiple chunks at once, with the form ‘N + x’ (with or without the spaces), where ‘x’ is the number of additional chunks to run. (I.e. ‘N + 2’ runs three chunks.)

The command ‘P’ prints the chunk at the cursor, without running it. It is possible to print other chunks as well: ‘P - 1’ prints the previous chunk, ‘P - 2’ the one before that, etc., ‘P + 1’ prints the next chunk, etc.

The reader is welcome to inspect R objects, or run arbitrary R code between the ‘N’ and ‘P’ commands.


Gabor Csardi <>

See Also

install_sand_packages to install all R packages needed for the book.


## Start with Chapter 2

## Run first code chunk

## Run next code chunk

## Jump to Chapter 5

## Run first code chunk in Chapter 5
## It will create a plot

Example output

Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':


Loading required package: igraphdata

Statistical Analysis of Network Data with R
Type in C2 (+ENTER) to start with Chapter 2.
sh: 1: cannot create /dev/null: Permission denied
SAND Chapter 2, press N (+ENTER) to run the next code chunk 
<<< 2.1
g <- graph.formula(1-2, 1-3, 2-3, 2-4, 3-5, 4-5, 4-6,
                    4-7, 5-6, 6-7)
<<< 2.2
+ 7/7 vertices, named, from 50be9c5:
[1] 1 2 3 4 5 6 7
sh: 1: cannot create /dev/null: Permission denied
SAND Chapter 5, press N (+ENTER) to run the next code chunk 
<<< 5.1
set.seed(42) <-, 0.02)
plot(,, vertex.label=NA)

sand documentation built on July 8, 2020, 7:16 p.m.

Related to aaa-sand in sand...