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 asfobject.- 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 definedadmininconfig_pviem()and in the same order. For example, if the administrative columns defined inconfig_pviem()areadmin1andadmin2, thenadmin_colsshould be a character vector of length 2 containing the column names in the shapefile that correspond toadmin1andadmin2respectively.- dcolname
[character(1)]. This argument is deprecated. Please use the
admin_colsargument instead.- ...
Forces optional arguments to be passed by name and allows for future extensions without breaking existing code. Must be empty.
- level
[integer(1)]. This argument is deprecated. Please use the
max_levelargument instead.- max_level
[integer(1)]An integer specifying the maximum neighbor distance (in levels of adjacency) to retrieve. Default isInfmeaning to the maximum level possible. We have the same behavior asInfwhen 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.