| Title: | Pakistan Spatial Data Toolkit |
|---|---|
| Description: | Provides a tidy interface to Pakistan's official administrative boundary data from the United Nations Office for the Coordination of Humanitarian Affairs (OCHA). Downloads and caches spatial data at country, province, district, and tehsil levels as 'sf' objects compatible with the 'tidyverse' and geospatial ecosystem. Includes utilities for geographic dictionary lookup, coordinate reference system selection, spatial measurement, and neighbour structure construction for use with 'spdep', 'ggplot2', 'leaflet', and related packages. |
| Authors: | Abdullah Umer [aut, cre] (ORCID: <https://orcid.org/0009-0008-4082-8394>) |
| Maintainer: | Abdullah Umer <[email protected]> |
| License: | GPL-3 |
| Version: | 1.2.1 |
| Built: | 2026-05-13 12:20:50 UTC |
| Source: | https://github.com/cran/pkmapr |
Get national boundary for Pakistan.
get_country(crs = 4326)get_country(crs = 4326)
crs |
Integer EPSG code. Default 4326 (WGS84). Use 32642 for
distance and area calculations. See |
Returns an sf object (class "sf" and "data.frame") with:
country_name |
Character. Name of the country ("Pakistan") |
country_code |
Character. ISO country code |
area_km2 |
Numeric. Area in square kilometres |
geometry |
MULTIPOLYGON. The national boundary geometry |
The output represents the complete national boundary of Pakistan.
pakistan <- get_country() plot(sf::st_geometry(pakistan)) print(pakistan$area_km2)pakistan <- get_country() plot(sf::st_geometry(pakistan)) print(pakistan$area_km2)
Get Pakistan district boundaries
get_districts(province = NULL, crs = 4326)get_districts(province = NULL, crs = 4326)
province |
Character. Filter to one province by exact name.
Matching is case-insensitive. Run |
crs |
Integer EPSG code. Default 4326 (WGS84). Use 32642 for
distance and area calculations. See |
Returns an sf object (class "sf" and "data.frame") with:
province_name |
Character. Parent province name |
district_name |
Character. District name |
district_code |
Character. Unique district identifier code (e.g., "PK603") |
area_km2 |
Numeric. Area in square kilometres for each district |
geometry |
MULTIPOLYGON. District boundary geometries |
When province is specified, the output contains only districts
within that province. The output represents administrative boundaries
at the district level.
# All districts all_districts <- get_districts() # Filter to Punjab province (case-insensitive) punjab_districts <- get_districts(province = "Punjab") punjab_districts <- get_districts(province = "punjab") # Same result plot(sf::st_geometry(punjab_districts))# All districts all_districts <- get_districts() # Filter to Punjab province (case-insensitive) punjab_districts <- get_districts(province = "Punjab") punjab_districts <- get_districts(province = "punjab") # Same result plot(sf::st_geometry(punjab_districts))
Get Pakistan province boundaries
get_provinces(crs = 4326)get_provinces(crs = 4326)
crs |
Integer EPSG code. Default 4326 (WGS84). Use 32642 for
distance and area calculations. See |
Returns an sf object (class "sf" and "data.frame") with:
province_name |
Character. Name of the province (e.g., "Punjab", "Sindh") |
province_code |
Character. Unique province identifier code |
area_km2 |
Numeric. Area in square kilometres for each province |
geometry |
MULTIPOLYGON. Province boundary geometries |
The output represents the administrative boundaries of Pakistan's provinces and territories.
provinces <- get_provinces() plot(sf::st_geometry(provinces)) head(provinces)provinces <- get_provinces() plot(sf::st_geometry(provinces)) head(provinces)
Get Pakistan tehsil boundaries
get_tehsils(district = NULL, province = NULL, crs = 4326)get_tehsils(district = NULL, province = NULL, crs = 4326)
district |
Character. Filter to one district by exact name. Matching is case-insensitive. NULL returns all. |
province |
Character. Filter to one province by exact name. Matching is case-insensitive. NULL returns all. If both district and province are supplied, district takes precedence. |
crs |
Integer EPSG code. Default 4326 (WGS84). Use 32642 for
distance and area calculations. See |
Returns an sf object (class "sf" and "data.frame") with:
province_name |
Character. Parent province name |
district_name |
Character. Parent district name |
tehsil_name |
Character. Tehsil name |
tehsil_code |
Character. Unique tehsil identifier code |
area_km2 |
Numeric. Area in square kilometres for each tehsil |
geometry |
MULTIPOLYGON. Tehsil boundary geometries |
The output represents the finest available administrative boundaries in pkmapr, suitable for high-resolution spatial analysis, local-level mapping, and joining with tehsil-level census or survey data.
# All tehsils all_tehsils <- get_tehsils() # Filter to Sindh province sindh_tehsils <- get_tehsils(province = "Sindh") sindh_tehsils <- get_tehsils(province = "sindh") # Case-insensitive # Filter to Lahore district lahore_tehsils <- get_tehsils(district = "Lahore") lahore_tehsils <- get_tehsils(district = "lahore") # Case-insensitive plot(sf::st_geometry(lahore_tehsils))# All tehsils all_tehsils <- get_tehsils() # Filter to Sindh province sindh_tehsils <- get_tehsils(province = "Sindh") sindh_tehsils <- get_tehsils(province = "sindh") # Case-insensitive # Filter to Lahore district lahore_tehsils <- get_tehsils(district = "Lahore") lahore_tehsils <- get_tehsils(district = "lahore") # Case-insensitive plot(sf::st_geometry(lahore_tehsils))
Computes accurate areas by reprojecting to UTM Zone 42N before measurement. Returns the input object with area_km2 added or updated.
pk_area(x)pk_area(x)
x |
An sf object with polygon geometries. |
Returns the input sf object (class "sf" and "data.frame") with the
area_km2 |
Numeric column added or updated, representing the area of each polygon in square kilometres. |
districts <- get_districts() districts <- pk_area(districts) head(districts$area_km2)districts <- get_districts() districts <- pk_area(districts) head(districts$area_km2)
Returns a leaflet map pre-zoomed to Pakistan's extent as a starting point for building custom interactive maps.
pk_basemap(provider = "CartoDB.Positron")pk_basemap(provider = "CartoDB.Positron")
provider |
Character. Tile provider. Default "CartoDB.Positron". |
Returns a leaflet object (class "leaflet" and "htmlwidget") with the following configuration:
Provider tiles |
Specified tile provider (default: CartoDB.Positron) |
Bounds |
Pre-zoomed to Pakistan's extent: longitude 60.9°E to 77.8°E, latitude 23.5°N to 37.1°N |
The output is a fully customizable leaflet basemap ready for adding layers (e.g., administrative boundaries, point data, markers). Use this as a starting point for building custom interactive maps.
# Default basemap with CartoDB.Positron tiles pk_basemap() # Alternative tile provider pk_basemap(provider = "OpenStreetMap")# Default basemap with CartoDB.Positron tiles pk_basemap() # Alternative tile provider pk_basemap(provider = "OpenStreetMap")
Retrieves the spatial extent (bounding box) of a specific administrative unit by name and level. Useful for setting map views or cropping other spatial data.
pk_bbox(name, level = c("province", "district", "tehsil"))pk_bbox(name, level = c("province", "district", "tehsil"))
name |
Character. Name of the administrative unit (e.g., "Punjab", "Lahore"). |
level |
Character. One of "province", "district", or "tehsil". |
Returns a bbox object (class "bbox") with named elements:
xmin |
Minimum x-coordinate (longitude or easting) |
ymin |
Minimum y-coordinate (latitude or northing) |
xmax |
Maximum x-coordinate |
ymax |
Maximum y-coordinate |
The output is suitable for use with ggplot2::coord_sf(xlim = c(xmin, xmax), ylim = c(ymin, ymax))
or leaflet::fitBounds(lng1 = xmin, lat1 = ymin, lng2 = xmax, lat2 = ymax).
It represents the rectangular extent that exactly contains the requested
administrative unit.
If you see an error like object 'xxx' not found when using this
function, the issue is likely in your data preparation, not pk_bbox().
Test the function directly: pk_bbox("Punjab", level = "province").
If that works, check that your data has the expected column names.
# Get bounding box for Lahore district bb <- pk_bbox("Lahore", level = "district") print(bb) # Use with ggplot2 library(ggplot2) districts <- get_districts() bb_punjab <- pk_bbox("Punjab", level = "province") ggplot() + geom_sf(data = districts) + coord_sf(xlim = c(bb_punjab["xmin"], bb_punjab["xmax"]), ylim = c(bb_punjab["ymin"], bb_punjab["ymax"]))# Get bounding box for Lahore district bb <- pk_bbox("Lahore", level = "district") print(bb) # Use with ggplot2 library(ggplot2) districts <- get_districts() bb_punjab <- pk_bbox("Punjab", level = "province") ggplot() + geom_sf(data = districts) + coord_sf(xlim = c(bb_punjab["xmin"], bb_punjab["xmax"]), ylim = c(bb_punjab["ymin"], bb_punjab["ymax"]))
Reprojects to UTM Zone 42N internally so buffer distances are in kilometres, then returns buffers in the original CRS.
pk_buffer(x, dist_km)pk_buffer(x, dist_km)
x |
An sf object. |
dist_km |
Numeric. Buffer distance in kilometres. |
Returns an sf object with the same attributes as x but with
geometries transformed to buffers of radius dist_km kilometres.
The output CRS is identical to the input CRS (reprojected back from UTM Zone 42N after buffering). This ensures buffers are circular in projected space with accurate kilometre distances.
districts <- get_districts() buffered <- pk_buffer(districts, dist_km = 10)districts <- get_districts() buffered <- pk_buffer(districts, dist_km = 10)
Returns polygon centroids as a point sf object with only geometry (attributes are dropped to avoid warnings about constant attributes).
pk_centroid(x)pk_centroid(x)
x |
An sf object with polygon geometries. |
Returns an sf point object (class "sf") with:
geometry |
Point geometries representing the centroids of input polygons |
Centroids represent the geometric center of each polygon, useful for point-based visualisation, distance calculations, or as nodes for spatial network analysis.
districts <- get_districts() centres <- pk_centroid(districts) plot(centres)districts <- get_districts() centres <- pk_centroid(districts) plot(centres)
Examines the geographic extent of an sf object and recommends the most appropriate projected coordinate reference system for metric operations. Pakistan spans UTM zones 41N, 42N, and 43N; national-level analyses benefit from an equal-area projection.
pk_crs_suggest(x)pk_crs_suggest(x)
x |
An sf object. |
Using WGS84 (EPSG:4326) for distance, area, or buffer operations produces inaccurate results as it measures in degrees rather than metres.
A named list:
Integer EPSG code for the recommended CRS.
Human-readable CRS name.
One-sentence explanation of the recommendation.
pk_crs_suggest(get_country()) pk_crs_suggest(get_districts(province = "Balochistan"))pk_crs_suggest(get_country()) pk_crs_suggest(get_districts(province = "Balochistan"))
Search and explore administrative names and codes for Pakistan.
pk_dictionary(level = NULL, name = NULL, code = NULL)pk_dictionary(level = NULL, name = NULL, code = NULL)
level |
Character. One of: "provinces", "districts", "tehsils". NULL (default) returns all levels. |
name |
Character. Filter by partial name (case-insensitive). |
code |
Character. Filter by partial P-code (case-insensitive). |
Returns a data frame (class "data.frame") with the following columns:
name |
Administrative unit name (e.g., "Lahore") |
level |
Administrative level: "provinces", "districts", or "tehsils" |
code |
P-code (unique identifier for the administrative unit) |
parent |
Parent administrative unit (province for districts, district for tehsils) |
The output represents a searchable dictionary of all administrative units in Pakistan. Use this function to explore available units, find codes, or validate input for other pkmapr functions.
All matching in pk_dictionary() is case-insensitive.
"Lahore", "lahore", and "LAHORE" all return the same results.
# All provinces pk_dictionary(level = "provinces") # Case-insensitive search for districts containing "lahore" pk_dictionary(level = "districts", name = "lahore") pk_dictionary(level = "districts", name = "LAHORE") # Same result # Search by code pk_dictionary(code = "PK6")# All provinces pk_dictionary(level = "provinces") # Case-insensitive search for districts containing "lahore" pk_dictionary(level = "districts", name = "lahore") pk_dictionary(level = "districts", name = "LAHORE") # Same result # Search by code pk_dictionary(code = "PK6")
Reprojects internally to UTM Zone 42N for accurate metric distances.
pk_distance(x, y, by = c("centroid", "edge"))pk_distance(x, y, by = c("centroid", "edge"))
x |
An sf object. |
y |
An sf object. |
by |
Character. "centroid" (default) for centroid-to-centroid distances. "edge" for nearest-point-on-boundary distances. |
Returns a numeric matrix (class "matrix") of distances in kilometres,
with dimensions nrow(x) by nrow(y).
When by = "centroid", distances are measured between polygon
centroids. When by = "edge", distances are measured between the
closest points on polygon boundaries. The output represents the
shortest straight-line distance between features.
provinces <- get_provinces() d <- pk_distance(provinces, provinces) print(d) # Edge-to-edge distances d_edge <- pk_distance(provinces, provinces, by = "edge")provinces <- get_provinces() d <- pk_distance(provinces, provinces) print(d) # Edge-to-edge distances d_edge <- pk_distance(provinces, provinces, by = "edge")
Returns the geometric intersection of two sf objects with CRS alignment handled automatically.
pk_intersect(x, y)pk_intersect(x, y)
x |
An sf object. |
y |
An sf object. |
Returns an sf object containing the geometric intersection of x and y:
geometry |
Points, lines, or polygons where |
... |
All attribute columns from both |
The output CRS matches x. Empty geometries (no intersection) are dropped.
Output represents areas/features common to both input layers.
districts <- get_districts() buffered <- pk_buffer(districts, dist_km = 10) intersected <- pk_intersect(districts, buffered)districts <- get_districts() buffered <- pk_buffer(districts, dist_km = 10) intersected <- pk_intersect(districts, buffered)
Performs a left join of external data to a pkmapr spatial object, with automatic validation of matching keys. Uses code columns (e.g., district_code, tehsil_code, province_code) wherever possible to ensure reliable joins even when names change or have spelling variations.
pk_join(spatial, data, by)pk_join(spatial, data, by)
spatial |
An sf object from a pkmapr geometry function (e.g.,
|
data |
A data frame to join. Must contain the column specified in |
by |
Character. Column name present in both spatial and data.
Recommended to use code columns ( |
Returns the spatial sf object (class "sf" and "data.frame") with
all columns from data joined to the matching rows.
The output preserves:
geometry |
The original spatial geometries unchanged |
spatial_attributes |
All original columns from the spatial object |
data_columns |
All columns from |
Rows in data that do not match any spatial unit generate a warning
and receive NA values for spatial attributes in the joined result.
Rows in the spatial object that have no match in data retain their
original attributes but receive NA for the joined data columns.
After joining, always inspect names(result) to check for column name
conflicts. If your data shares column names with the spatial object (e.g.,
province_name, district_name), both versions will be preserved with
.x and .y suffixes. Rename or select the appropriate columns before
further analysis.
districts <- get_districts() my_data <- data.frame(district_code = "PK603", value = 42) joined <- pk_join(districts, my_data, by = "district_code") print(names(joined)) # Example with missing match (generates warning) bad_data <- data.frame(district_code = c("PK603", "INVALID_CODE"), value = c(42, 99)) joined_bad <- pk_join(districts, bad_data, by = "district_code")districts <- get_districts() my_data <- data.frame(district_code = "PK603", value = 42) joined <- pk_join(districts, my_data, by = "district_code") print(names(joined)) # Example with missing match (generates warning) bad_data <- data.frame(district_code = c("PK603", "INVALID_CODE"), value = c(42, 99)) joined_bad <- pk_join(districts, bad_data, by = "district_code")
Produces a ggplot2 map for rapid exploratory visualisation. Returns a ggplot object that can be extended with standard ggplot2 layers.
pk_map(x, fill = NULL, title = NULL, ...)pk_map(x, fill = NULL, title = NULL, ...)
x |
An sf object. |
fill |
Character. Column name to use as fill variable. NULL (default) produces an outline map. |
title |
Character. Map title. NULL for no title. |
... |
Additional arguments passed to |
Returns a ggplot object (class "gg" and "ggplot") representing a choropleth map.
When fill = NULL, the output is an outline map with grey90 fill
and white borders, useful for context or reference.
When a fill variable is provided, the output uses a viridis color
scale with automatic legend, for visualizing spatial distributions
of continuous variables (e.g., area, population, density).
The returned ggplot object can be extended with additional layers, themes, or scales using standard ggplot2 syntax.
# Outline map of provinces pk_map(get_provinces()) # Choropleth map with fill variable pk_map(get_provinces(), fill = "area_km2", title = "Province areas")# Outline map of provinces pk_map(get_provinces()) # Choropleth map with fill variable pk_map(get_provinces(), fill = "area_km2", title = "Province areas")
Produces an interactive leaflet map. Returns a leaflet object that can be extended with standard leaflet functions.
pk_map_interactive(x, fill = NULL, popup = NULL, ...)pk_map_interactive(x, fill = NULL, popup = NULL, ...)
x |
An sf object. |
fill |
Character. Column name for choropleth fill. NULL produces an outline map. |
popup |
Character vector. Column names to display in click popups. |
... |
Additional arguments passed to |
Returns a leaflet object (class "leaflet" and "htmlwidget") representing an interactive web map.
When fill = NULL, the output shows polygon outlines only.
When a fill variable is provided, the output renders polygons with:
fillColor |
Color-coded by the fill variable using the viridis palette |
fillOpacity |
0.7 (semi-transparent for layer visibility) |
color |
White borders for polygon boundaries |
popup |
HTML popups showing selected attributes on click |
The map includes a legend for the fill variable and uses the CartoDB.Positron tile provider as the basemap.
districts <- get_districts() pk_map_interactive(districts, fill = "area_km2", popup = c("district_name", "area_km2"))districts <- get_districts() pk_map_interactive(districts, fill = "area_km2", popup = c("district_name", "area_km2"))
Builds a contiguity or distance-based spatial neighbours structure for direct use with spdep and spatialreg. Handles Pakistan-specific complexities including non-contiguous units and disputed boundaries.
pk_neighbors( x, style = c("queen", "rook", "knn"), k = NULL, disputed = c("exclude", "include", "flag") )pk_neighbors( x, style = c("queen", "rook", "knn"), k = NULL, disputed = c("exclude", "include", "flag") )
x |
An sf object with polygon geometries. |
style |
Character. Neighbour definition: "queen" (shared boundary point, default), "rook" (shared edge), or "knn" (k nearest centroids). |
k |
Integer. Number of nearest neighbours. Required when
|
disputed |
Character. Treatment of non-contiguous units and disputed boundaries:
|
Returns a named list (class "list") with the following:
nb |
An spdep nb object (class "nb") containing the neighbour relationships. Each element is an integer vector of neighbour indices. |
listw |
A row-standardised spdep listw object (class "listw"),
ready for |
boundary_note |
Character string. Present only when
|
The output is a complete spatial weights structure for
use in spatial autocorrelation tests (Moran's I), local indicators of
spatial association (LISA), and spatial regression models (SAR, SEM, etc.).
The nb defines the neighbour graph; the listw
provides the row-standardized weights matrix.
Gilgit-Baltistan and Azad Kashmir might break some spatial statistics.
The disputed argument controls how the Line of Control and
special administrative boundaries flagged in the OCHA source data are
treated, offering better control over analytical decisions.
districts <- get_districts() w <- pk_neighbors(districts) # Calculate Moran's I using spdep moran_result <- spdep::moran.test(districts$area_km2, w$listw) print(moran_result) # Queen contiguity (default) w_queen <- pk_neighbors(districts, style = "queen") # K-nearest neighbours (k=5) w_knn <- pk_neighbors(districts, style = "knn", k = 5) # Flag disputed boundaries for documentation w_flagged <- pk_neighbors(districts, disputed = "flag") if (!is.null(w_flagged$boundary_note)) cat(w_flagged$boundary_note)districts <- get_districts() w <- pk_neighbors(districts) # Calculate Moran's I using spdep moran_result <- spdep::moran.test(districts$area_km2, w$listw) print(moran_result) # Queen contiguity (default) w_queen <- pk_neighbors(districts, style = "queen") # K-nearest neighbours (k=5) w_knn <- pk_neighbors(districts, style = "knn", k = 5) # Flag disputed boundaries for documentation w_flagged <- pk_neighbors(districts, disputed = "flag") if (!is.null(w_flagged$boundary_note)) cat(w_flagged$boundary_note)
For each point in points, identifies which polygon it falls
within and joins that polygon's attributes to the point record.
pk_points_in(points, polygons, return_all = TRUE)pk_points_in(points, polygons, return_all = TRUE)
points |
An sf object with point geometries. |
polygons |
An sf object with polygon geometries. |
return_all |
Logical. Keep unmatched points with NA polygon attributes (TRUE, default) or drop them (FALSE). |
Returns an sf object of the same class as points with:
geometry |
Point geometries (unchanged) |
... |
Attribute columns from |
Points that fall outside all polygons receive NA values for all polygon
attributes when return_all = TRUE. When return_all = FALSE, such points
are removed entirely.
The output represents point locations with their containing administrative unit attributes attached, allowing spatial aggregations and unit-based analyses.
# Get district boundaries districts <- get_districts() # Create sample points (or use your own sf object) set.seed(123) sample_points <- sf::st_sample(districts, size = 50) sample_points_sf <- sf::st_sf(geometry = sample_points) # Assign points to districts points_with_districts <- pk_points_in(sample_points_sf, districts) print(head(points_with_districts))# Get district boundaries districts <- get_districts() # Create sample points (or use your own sf object) set.seed(123) sample_points <- sf::st_sample(districts, size = 50) sample_points_sf <- sf::st_sf(geometry = sample_points) # Assign points to districts points_with_districts <- pk_points_in(sample_points_sf, districts) print(head(points_with_districts))
Convenience wrapper around sf::st_transform() with a default
of UTM Zone 42N, appropriate for most Pakistan analyses requiring
accurate distance, area, or buffer operations.
pk_project(x, crs = 32642)pk_project(x, crs = 32642)
x |
An sf object. |
crs |
Integer EPSG code. Default 32642 (WGS84 / UTM Zone 42N). |
Returns the sf object reprojected to the specified CRS. The output has the same attributes and geometry type as the input, but coordinates are transformed to the new projection. UTM Zone 42N (EPSG:32642) preserves distances and areas accurately across most but not all of Pakistan.
districts <- get_districts() projected <- pk_project(districts) sf::st_crs(projected)$epsg # Should be 32642districts <- get_districts() projected <- pk_project(districts) sf::st_crs(projected)$epsg # Should be 32642
Search for administrative units by partial name or code across all levels (provinces, districts, tehsils).
pk_search(query, fuzzy = FALSE)pk_search(query, fuzzy = FALSE)
query |
Character. Search term (partial match, case-insensitive). |
fuzzy |
Logical. If TRUE, uses fuzzy matching for typos. Default FALSE. Warning: Fuzzy matching can be slower and may return unexpected matches for short or common queries. |
Returns a data frame (class "data.frame") with the following columns:
name |
Matching administrative unit name(s) |
level |
Administrative level of each match |
code |
P-code of each match |
parent |
Parent unit of each match |
The output represents all administrative units that match the search query. When no matches are found, returns invisible NULL with a warning message. When fuzzy matching is enabled, the output may include approximate matches that could be useful for handling typos or spelling variations.
All matching in pk_search() is case-insensitive by default.
"Lahore", "lahore", and "LAHORE" all return the same results.
When fuzzy = TRUE, the function uses approximate string matching
to handle typos and spelling variations. For example, "lahor" will
match "Lahore". This is useful for interactive exploration but
may return unexpected results for ambiguous queries.
# Case-insensitive search pk_search("lahore") # Returns Lahore district and tehsils pk_search("LAHORE") # Same result # Fuzzy search for misspelled "lahore" pk_search("lahor", fuzzy = TRUE) pk_search("lahre", fuzzy = TRUE) # Search by code pk_search("PK6")# Case-insensitive search pk_search("lahore") # Returns Lahore district and tehsils pk_search("LAHORE") # Same result # Fuzzy search for misspelled "lahore" pk_search("lahor", fuzzy = TRUE) pk_search("lahre", fuzzy = TRUE) # Search by code pk_search("PK6")
Merges polygons sharing the same value in a grouping column and recalculates area_km2.
pk_union(x, by)pk_union(x, by)
x |
An sf object. |
by |
Character. Column name to group by. |
Returns a dissolved sf object (class "sf" and "data.frame") with:
geometry |
MULTIPOLYGON geometries created by merging adjacent polygons |
by_column |
The unique grouping values (one row per group) |
area_km2 |
Recalculated area in square kilometres for each dissolved polygon |
Polygons that are not spatially adjacent but share the same group value
will become MULTIPOLYGON objects. Invalid geometries are repaired automatically
using sf::st_make_valid().
tehsils <- get_tehsils() by_district <- pk_union(tehsils, by = "district_name")tehsils <- get_tehsils() by_district <- pk_union(tehsils, by = "district_name")
Compares the installed version of pkmapr with the latest release available on GitHub.
pk_version(quiet = FALSE)pk_version(quiet = FALSE)
quiet |
Logical. If FALSE (default), prints status messages to console. If TRUE, returns the version information silently. |
Returns invisibly a list (class "list") with the following components:
installed |
Character string. The currently installed version number. |
latest |
Character string or NA. The latest version number from GitHub, or NA if the check failed (e.g., no internet connection). |
pk_version() # Silent mode for programmatic use vers <- pk_version(quiet = TRUE) if (!is.na(vers$latest) && vers$installed != vers$latest) { message("Update recommended!") }pk_version() # Silent mode for programmatic use vers <- pk_version(quiet = TRUE) if (!is.na(vers$latest) && vers$installed != vers$latest) { message("Update recommended!") }