The CShapes R Package

R is a free statistical software package, available from Once R is running on your system, you can use the built-in package manager to install the cshapes package:

  1. Install R from CRAN.
  2. Install the cshapes package using R's package manager. Alternatively, type
    > install.packages("cshapes", dependencies = TRUE)
    on the R console. This will also install other R extensions required by cshapes.

Using CShapes from R

The following R code loads the cshapes package, creates a matrix with distances between country capitals for the international system in 2002 and writes the matrix to a file. The rows and columns in this matrix are labeled with codes according to the Gleditsch & Ward system. If you need COW codes, add the useGW=F option to the distmatrix() call.
dmat <- distmatrix(as.Date("2002-1-1"), type="capdist")
write.table(dmat, "distmat2002.txt", row.names=T, col.names=T)

Many applications require an adjacency matrix, which can be created from the distance matrix. Here, we code all countries to be adjacent if their capital distance does not exceed 900 km.
adjmat <- ifelse(dmat > 900, 0, 1)
diag(adjmat) <- 0
write.table(adjmat, "adjmat2002.txt", row.names=T, col.names=T)


Here you can find a set of examples for using R with cshapes. We will keep posting new examples as we get them.

Additional Information

Other examples of using the cshapes R package can be found in our R Journal article.

CShapes on R-Forge

The CShapes development site is hosted on R-Forge.