install.packages("spanishoddata",
repos = c("https://e-kotov.r-universe.dev", "https://cloud.r-project.org"))
<- spanishoddata::spod_get_zones("municip", ver = 2) zones
Missing column names in municipal population CSV
tabular data
metadata
importance: low
Status: ✅ resolved
Importance: 1 - low
Summary: CSV file with municipal population data is missing column names.
Expected Results: The dataset should have ID
and population
columns.
Resolution: resolved with https://github.com/Robinlovelace/spanishoddata/pull/25 in {spanishoddata}
R package.
To get valid spatial data, use spanishoddata::
spod_get_zones()
Steps to Reproduce
- Load Data
Load libraries and define data files.
library(tidyverse)
library(here)
library(DT)
<- here("data/raw_data/v2/zonificacion/zonificacion_municipios/poblacion_municipios.csv") municipality_population_file
Load the data and join the municipality names to the boundaries.
<- read.delim(municipality_population_file, sep = "|") municipality_population
Results
- Missing column names
names(municipality_population)
[1] "X01001" "X2925.0"
str(municipality_population)
'data.frame': 2617 obs. of 2 variables:
$ X01001 : chr "01002" "01004_AM" "01009_AM" "01010" ...
$ X2925.0: num 10307 3005 4599 2951 4314 ...
- Preview of the municipal population table
::datatable(municipality_population) DT
Links to the original files
source(here("R/901-download-helpers.R"))
<- load_latest_v2_xml()
files
# Filter relevant files
<- files |>
relevant_files filter(basename(local_path) %in% basename(c(municipality_population_file)) )
# Create HTML links
<- relevant_files |>
relevant_files mutate(target_url = paste0("<a href='", target_url, "' target='_blank'>", target_url, "</a>"))
# Render the DT table with links
datatable(relevant_files, escape = FALSE, options = list(pageLength = 5))