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.
N<enter> to run the next chunk of code,
C<x> to jump to Chapter
x is between
2 and 11. E.g.
C6<enter> resets R and “loads” Chapter
P<enter> prints the next code chunk to be run (without
actually running it).
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:
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 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
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 <email@example.com>
install_sand_packages to install all R packages
needed for the book.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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': union 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 library(igraph) 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 V(g) >>> + 7/7 vertices, named, from 50be9c5:  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 library(sand) set.seed(42) g.er <- erdos.renyi.game(100, 0.02) plot(g.er, layout=layout.circle, vertex.label=NA)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.