Skip to contents

Retrieve the neighbors for each administrative unit in a shapefile up to a specified level.

Usage

get_neighbors(
  shapefile,
  admin_cols = dcolname,
  dcolname = deprecated(),
  ...,
  level = deprecated(),
  max_level = if (lifecycle::is_present(level)) level else Inf
)

Arguments

shapefile

[st::sf(1)] A shapefile object containing administrative unit geometries as a sf object.

admin_cols

[character] A character vector of column names in the shapefile to be used for identifying the administrative units. The number of columns should be the same as the number of administrative columns defined admin in config_pviem() and in the same order. For example, if the administrative columns defined in config_pviem() are admin1 and admin2, then admin_cols should be a character vector of length 2 containing the column names in the shapefile that correspond to admin1 and admin2 respectively.

dcolname

[character(1)] [Deprecated]. This argument is deprecated. Please use the admin_cols argument instead.

...

Forces optional arguments to be passed by name and allows for future extensions without breaking existing code. Must be empty.

level

[integer(1)] [Deprecated]. This argument is deprecated. Please use the max_level argument instead.

max_level

[integer(1)] An integer specifying the maximum neighbor distance (in levels of adjacency) to retrieve. Default is Inf meaning to the maximum level possible. We have the same behavior as Inf when the specified level cannot be reached for the given administrative unit.

Value

[list<character(1) = list<character>>] Named list specifying the list of neighboring administrative units by level for each administrative unit in shapefile as a list of character vectors. The names of the outer list are the administrative unit identifiers (constructed by joining the columns specified in admin_cols) and the values are lists where each element is a vector of neighboring administrative unit identifiers for a specific level up to the maximum level defined by max_level or the maximum level possible if max_level is higher than the maximum level possible. The nth element of the inner list corresponds to the level n neighbors.

Details

The function retrieves the direct neighbors for each administrative unit in the shapefile object and then retrieves the subsequent level neighbors recursively up to the specified/maximum level.