install.packages("spanishoddata",
repos = c("https://e-kotov.r-universe.dev", "https://cloud.r-project.org"))
zones <- spanishoddata::spod_get_zones("municip", ver = 2)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)
municipality_population_file <- here("data/raw_data/v2/zonificacion/zonificacion_municipios/poblacion_municipios.csv")Load the data and join the municipality names to the boundaries.
municipality_population <- read.delim(municipality_population_file, sep = "|")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
DT::datatable(municipality_population)Links to the original files
source(here("R/901-download-helpers.R"))
files <- load_latest_v2_xml()
# Filter relevant files
relevant_files <- 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))