Which countries share a land border with which, as a tidy edge list –
built from polygon topology (sf::st_touches()), so it reflects the same
curated geometry as the rest of the package. Powers neighbors().
Arguments
- scale
Natural Earth resolution to compute adjacency from. Coarser scales simplify small slivers and may miss a handful of short borders.
"large"needs the non-CRANrnaturalearthhirespackage; seeworld_geometry().- region
Optional region subset (see
world_geometry()); a pair is only reported when both countries remain in the subset.
Value
A tibble, one row per bordering pair: iso3c_a, country_a,
iso3c_b, country_b. Each unordered pair appears once, with
iso3c_a <= iso3c_b alphabetically.
Turning it into a graph
igraph::graph_from_data_frame() takes the first two columns as the edge
endpoints, so pass only the two code columns – handing it the whole tibble
would build edges from each country's code to its own name:
Attaching igraph also masks neighbors(), which it exports too, so call
that one as countryatlas::neighbors() from then on.
Examples
# \donttest{
if (requireNamespace("sf", quietly = TRUE) &&
requireNamespace("rnaturalearth", quietly = TRUE)) {
head(country_borders(region = "Europe"))
# The whole world is only a little dearer: a fraction of a second.
nrow(country_borders())
}
#> [1] 310
# }
