From 58f4e445cfa4d9015fcc54f1957ea94079a55153 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:30:31 -0700 Subject: [PATCH 01/13] ignore DSstore --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 1 + 2 files changed, 1 insertion(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..80f880920d508037d9898c1b137803de3b92a0fe GIT binary patch literal 6148 zcmeHK%}&BV5Z(opHpGO3CLA~MN)!yD#!Ibu@Jfvy)F8D48cUZzu?IrZv%Z3_;N2(i z5quD@UYz}bNI;KD%uF)-?at4(`)#w^A%swS=#>e{6G9A7fhiN31tR=H=Om>qtAJF@ z5wy$BE${Z`BGIs{42ZqUkS)?CK8Y6W-_+OTwVE4n7vhbl)AwiRcS5_9@~5vdIOp3D2HhpW+Pu1jrJ}7cON@;{+a|11q_A`eDGswj51-h{ymkfD9}r1NuZW za?AO8_*TdOGVq5Ci1UGg3bZsP3gyuOjVu8GGhmhieNjt@9H!CIm?#7f2vwWtP^f%5%+F*vp_W2ykpX02mVvYy=EePg@_qe3n}j1| z02%mK4A4x?soAh3eYegnPTaK&^afOjh)WbsQ=lWSVu%%2aRF2c*qP`6S{f6DU;)7& N0Z9Wk$iS~M@Ch&SVsiih literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore index c833a2c..86fa0f8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .RData .Ruserdata inst/doc +.DS_Store From ea32c35731f1637ea04ba043d11b76a0efd3e97c Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:28:46 -0700 Subject: [PATCH 02/13] municipality id --- R/data-cleaning.R | 16 +- R/id-for-municipality.R | 422 ++++++++++++++++++++++ tests/testthat/test-id-for-municipality.R | 67 ++++ 3 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 R/id-for-municipality.R create mode 100644 tests/testthat/test-id-for-municipality.R diff --git a/R/data-cleaning.R b/R/data-cleaning.R index 639fc43..d4a6b4d 100644 --- a/R/data-cleaning.R +++ b/R/data-cleaning.R @@ -64,14 +64,22 @@ assign_state_perpetrator_levels <- function(dataframe, simplify=FALSE){ de$state_perpetrator <- str_to_title(de$state_perpetrator) de$state_perpetrator <- fct_na_value_to_level(de$state_perpetrator, level = "Unknown") if (simplify){ + sp_levels_in_order <- c("Unknown", "No", "Indirect", "Mutiny", "Yes") + de$state_perpetrator <- fct_collapse(de$state_perpetrator, Yes = c("Yes", "Likely Yes", "Presumed Yes"), Indirect = c("Indirect"), No = c("No", "Likely No"), Mutiny = c("In Mutiny"), Unknown = c("Unknown", "Disputed", "Suspected") ) %>% suppressWarnings() + + if(length(levels(de$state_responsibility)) > length(lev$state_responsibility$levels)) { + warning(paste("Unknown state_perpetrator level:", + setdiff(levels(de$state_perpetrator), sp_levels_in_order), "\n")) + } + de$state_perpetrator <- fct_relevel(de$state_perpetrator, - c("Unknown", "No", "Indirect", "Mutiny", "Yes")) # default ordering + sp_levels_in_order) # default ordering } return(de) } @@ -136,6 +144,12 @@ assign_state_responsibility_levels <- function(dataframe, simplify=FALSE){ Unknown = c("Unknown", "Unclear", "Disputed") ) %>% suppressWarnings() + + if(length(levels(de$state_responsibility)) > length(lev$state_responsibility$levels)) { + warning(paste("Unknown state_responsibility level:", + setdiff(levels(de$state_responsibility), lev$state_responsibility$levels), "\n")) + } + de$state_responsibility <- fct_relevel(de$state_responsibility, lev$state_responsibility$levels) %>% suppressWarnings() diff --git a/R/id-for-municipality.R b/R/id-for-municipality.R new file mode 100644 index 0000000..7148d38 --- /dev/null +++ b/R/id-for-municipality.R @@ -0,0 +1,422 @@ +anexo_municipios <- readr::read_csv(here::here("data", "anexo_municipios_de_bolivia.csv")) +# anexo_municipios <- read_rds("data/anexo_municipios.rds") + +#' Rename Columns in a Dataframe for Standardization +#' +#' This function renames specific columns in a dataframe to standardize their names. +#' It ensures that the columns `municipality`, `province`, and `department` are present, renaming existing columns +#' (`municipio`, `provincia`, `departamento`) if necessary. Additionally, it renames any column starting with `codigo` +#' to `cod.mun`. +#' +#' @param dataframe A dataframe containing the columns to be standardized. +#' +#' @return A dataframe with standardized column names. +#' +#' @details +#' - The function checks for the presence of `municipality`, `province`, and `department`. +#' If these columns are missing, it renames `municipio`, `provincia`, and `departamento` to their English equivalents. +#' - Any column name starting with `codigo` is renamed to `cod.mun`. +#' +#' @examples +#' library(dplyr) +#' # Example dataframe +#' df <- data.frame( +#' municipio = c("La Paz", "Cochabamba"), +#' provincia = c("Pedro Domingo Murillo", "Cercado"), +#' departamento = c("La Paz", "Cochabamba"), +#' codigo123 = c(101, 102) +#' ) +#' +#' # Rename columns +#' renamed_df <- rename_anexo_columns(df) +#' print(names(renamed_df)) # Should include "municipality", "province", "department", "cod.mun" +#' +#' @importFrom dplyr rename rename_with starts_with +#' @export +rename_anexo_columns <- function(dataframe) { + # Check if destination columns are missing and perform renaming accordingly + if (!"municipality" %in% names(dataframe)) { + dataframe <- dataframe %>% + dplyr::rename(municipality = municipio) + } + if (!"province" %in% names(dataframe)) { + dataframe <- dataframe %>% + dplyr::rename(province = provincia) + } + if (!"department" %in% names(dataframe)) { + dataframe <- dataframe %>% + dplyr::rename(department = departamento) + } + + # Rename "codigo" columns to "cod.mun" without suffix + dataframe <- dataframe %>% + dplyr::rename_with(~ gsub("^codigo.*$", "cod.mun", .), .cols = dplyr::starts_with("codigo")) + + return(dataframe) +} + +#' Get the ID of a municipality based on its name +#' +#' Returns the unique identifier for a municipality based on its name and +#' optionally the department. These identifiers are the codes used +#' in the Bolivian government databases, known as INE codes for the +#' Instituto Nacional de Estadística. +#' +#' The function will warn the user if a municipality name without +#' department corresponds to multiple municipalities. In this case, the first +#' municipality found will be returned. (There are about a dozen such cases in Bolivia.) +#' +#' `id_for_municipality_2` is a version of the function that handles lookup +#' tables with lists of municipalities. It is relies on `muni_id_lookup_table`. +#' +#' @param municipality_i Name of the municipality to search for. +#' @param department_i Optional name of the department to filter by. +#' @param muni_list_table A data frame containing the municipality list table. +#' +#' @return The unique identifier for the municipality as listed in the `code` = +#' column of the `muni_list_table`. If no match is found, returns an empty string. +#' +#' @export +#' @examples +#' id_for_municipality("La Paz") # 020101 +#' id_for_municipality("La Paz", "La Paz") # 020101 +#' id_for_municipality("La Paz", "Cochabamba") # empty string +#' id_for_municipality("Potosí", "Potosí") # 050101 +#' id_for_municipality("Potosi") # 050101 +#' id_for_municipality("San Ramón") # 071103 +#' id_for_municipality("San Ramón", "Santa Cruz") # 071103 +#' id_for_municipality("San Ramón", "Beni") # 080702 +#' +#' id_for_municipality_2("zudanez") # "010301" +#' id_for_municipality_2("villa montes") # "060303" +#' id_for_municipality_2("villamontes") # "060303" +#' id_for_municipality_2("San Ignacio") # "070301" +#' id_for_municipality_2("San Ignacio", "Beni") # "080501" +id_for_municipality <- function(municipality_i, department_i = "", muni_list_table = anexo_municipios) { + if (is.na(municipality_i)){ + return(as.character(NA)) + } + + # Rename columns if necessary + if ("municipio" %in% names(muni_list_table) && !"municipality" %in% names(muni_list_table)) { + muni_list_table <- rename_anexo_columns(muni_list_table) + } + + # Ensure the first column is named "code" and formatted as character with leading zeros + names(muni_list_table)[1] <- "code" + # reformat first column as a character with leading zero + if (is.numeric(pull(muni_list_table,1))){ + muni_list_table <- muni_list_table %>% + mutate(code = as.character(sprintf("%06d", code))) + } + + # Filter by municipality + municipality_row <- muni_list_table %>% + dplyr::filter(str_equivalent(municipality, municipality_i)) + # print((municipality_row)) + + if (nrow(municipality_row) == 0) { + warning(paste("Municipality", municipality_i, "not found. Returning empty string.")) + return("") + } + + # Further filter by department if provided + if (department_i != "") { + municipality_row <- municipality_row %>% + dplyr::filter(str_equivalent(department, department_i)) + if (nrow(municipality_row) == 0) { + warning(paste("Municipality", municipality_i, "not found in department", department_i, ". Returning empty string.")) + return("") + } + } + + # Handle multiple results + if (nrow(municipality_row) > 1) { + warning(paste("Multiple municipalities found for", municipality_i, + if (department_i != "") paste("in department", department_i) else "without department", + ". Returning first ID found.")) + } + + return(unname(municipality_row$code[1])) +} + +#' Add an unique identifier for municipality (id_muni) column to a dataset +#' +#' @param dataset A dataframe with a column containing the name of the +#' municipality, named `municipality`. +#' @param id_variable_name The name of the new column to be created. Default is +#' `id_muni`. +#' @param muni_table A data frame containing the municipality list table. +#' @param overwrite A boolean indicating whether to overwrite an existing +#' column. +#' +#' @return A dataframe with a new column `id_muni` containing the unique +#' identifier for the municipality, placed before the `municipality` column. +#' +#' @export +add_id_for_municipality <- function(dataset, + id_variable_name = "id_muni", + muni_table = anexo_municipios, + overwrite = FALSE){ + if (!"municipality" %in% names(dataset)) { + stop("The dataset does not contain the 'municipality' column.") + } + if (id_variable_name %in% names(dataset) & + overwrite == FALSE) { + warning(paste("The dataset already contains the specified municipality id column. ", + "Call add_id_for_event() with overwrite = TRUE to replace it.")) + return(dataset) + } + + # dataset[[id_variable_name]] <- vapply(dataset$municipality, function(x) id_for_municipality(x, "", muni_table), + # FUN.VALUE = character(1)) + if ("muni_list" %in% names(muni_table)) { + # If the table has a list of municipalities, use id_for_municipality_2 + dataset[[id_variable_name]] <- vapply(seq_len(nrow(dataset)), function(i) { + id_for_municipality_2(dataset$municipality[i], dataset$department[i], muni_table) + }, FUN.VALUE = character(1)) + } else { + # Otherwise, use id_for_municipality + dataset[[id_variable_name]] <- vapply(seq_len(nrow(dataset)), function(i) { + id_for_municipality(dataset$municipality[i], dataset$department[i], muni_table) + }, FUN.VALUE = character(1)) + } + + dataset <- dataset %>% + dplyr::relocate(!!rlang::sym(id_variable_name), .before = municipality) + + return(dataset) +} + +muni_id_lookup_table <- readr::read_rds(here::here("data", "muni_id_lookup_table.rds")) + +#' @rdname id_for_municipality +#' @export +id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_table = muni_id_lookup_table) { + if (is.na(municipality_i)){ + return(as.character(NA)) + } + + assertthat::assert_that( + is.character(municipality_i), + is.character(department_i), + is.data.frame(muni_list_table), + "muni_list" %in% names(muni_list_table) + ) + + # Filter by municipality + municipality_row <- muni_list_table %>% + rowwise() %>% + dplyr::filter(str_equivalent_list(municipality_i, muni_list)) + + # Check if no rows match the municipality + if (nrow(municipality_row) == 0) { + warning(paste("Municipality", municipality_i, "not found. Returning empty string.")) + return("") + } + + # Further filter by department if provided + if (department_i != "") { + municipality_row <- municipality_row %>% + dplyr::filter(str_equivalent(department, department_i)) + if (nrow(municipality_row) == 0) { + warning(paste("Municipality", municipality_i, "not found in department", department_i, ". Returning empty string.")) + return("") + } + } + + # Handle multiple results + if (nrow(municipality_row) > 1) { + warning(paste("Multiple municipalities found for", municipality_i, + if (department_i != "") paste("in department", department_i) else "without department", + ". Returning first ID found.")) + } + + # Return the first matching id_muni + return(unname(municipality_row$id_muni[1])) +} + +#' Get Municipality Details from ID Vector +#' +#' This function looks up municipality details (municipality, province, and department) +#' from a list of municipality IDs in the given `muni_list_table`. +#' +#' @param id_muni A character vector of municipality IDs to look up. +#' @param muni_list_table A tibble or dataframe containing municipality information. +#' The table must have columns `cod.mun`, `municipality`, `province`, and `department`. +#' +#' @return A list with three components: +#' - `municipality`: A character vector of municipality names. +#' - `province`: A character vector of province names. +#' - `department`: A character vector of department names. +#' +#' @details +#' The function performs a lookup by matching the `id_muni` with the `cod.mun` column in `muni_list_table`. +#' If an ID is not found, the corresponding entries in the output list will be `NA`. +#' +#' @examples +#' library(dplyr) +#' # Example `muni_list_table` +#' anexo_municipios <- tibble::tibble( +#' cod.mun = c("010101", "010102", "010103"), +#' municipality = c("Sucre", "Yotala", "Poroma"), +#' province = c("Oropeza", "Oropeza", "Oropeza"), +#' department = c("Chuquisaca", "Chuquisaca", "Chuquisaca") +#' ) +#' +#' # Lookup municipality details +#' ids <- c("010101", "010102", "010999") +#' result <- municipality_from_id_muni(ids, anexo_municipios) +#' print(result) +#' +#' @export +municipality_vector_from_id <- function(id_muni, muni_list_table=anexo_municipios) { + + # Rename columns if necessary + if ("municipio" %in% names(muni_list_table) && !"municipality" %in% names(muni_list_table)) { + muni_list_table <- rename_anexo_columns(muni_list_table) + } + + # Ensure the first column is named "code" and formatted as character with leading zeros + names(muni_list_table)[1] <- "code" + # reformat first column as a character with leading zero + if (is.numeric(pull(muni_list_table,1))){ + muni_list_table <- muni_list_table %>% + mutate(code = as.character(sprintf("%06d", code))) + } + # Check if id_muni is a character vector + if (is.numeric(id_muni)) { + id_muni <- as.character(sprintf("%06d", id_muni)) + } + + # Perform a lookup for each ID in the id_muni + matched_rows <- muni_list_table[match(id_muni, muni_list_table$code), ] + + # Extract the required columns and handle missing matches + municipality <- matched_rows$municipality + province <- matched_rows$province + department <- matched_rows$department + + # Replace missing values (rows not found) with NA + municipality[is.na(matched_rows$code)] <- NA + province[is.na(matched_rows$code)] <- NA + department[is.na(matched_rows$code)] <- NA + + # Return the result as a list + list( + municipality = municipality, + province = province, + department = department + ) +} +# Get the geographic names from municipal ID +# +# These function retrieve the municipality, province, and department names +#' from the unique identifier (ID) of a municipality. The ID is a code used +#' in the Bolivian government databases, known as INE codes for the +#' Instituto Nacional de Estadística. +#' +#' @param id_muni A character vector of municipality IDs to look up. +#' @param muni_list_table A lookup dataframe containing municipality information. +#' +#' @return A string with the name of the municipality, province, or department. +#' +#' @rdname municipality_vector_from_id +#' @export +#' +#' @examples +#' municipality_name_from_id("020101") # "La Paz" +#' municipality_name_from_id("050101") # "Potosí" +#' municipality_name_from_id("071103") # "San Ramón" +#' municipality_name_from_id("080702") # "San Ramón" +#' municipality_name_from_id("010301") # "Villa Zudáñez" +#' province_name_from_id("020101") # "Murillo" +#' province_name_from_id("050101") # "Tomás Frías" +#' province_name_from_id("071103") # "Ñuflo de Chaves" +#' province_name_from_id("080702") # "Mamoré" +#' province_name_from_id("010301") # "Zudáñez" +#' province_name_from_id("060303") # "Gran Chaco" +#' province_name_from_id("070301") # "Velasco" +#' province_name_from_id("080501") # "Moxos" +#' department_name_from_id("020101") # "La Paz" +#' department_name_from_id("050101") # "Potosí" +#' department_name_from_id("071103") # "Santa Cruz" +#' department_name_from_id("080702") # "Beni" +#' department_name_from_id("010301") # "Chuquisaca" +#' department_name_from_id("060303") # "Tarija" +#' department_name_from_id("070301") # "Santa Cruz" +#' department_name_from_id("080501") # "Beni" +municipality_name_from_id <- function(id_muni, muni_list_table=anexo_municipios) { + vector <- municipality_vector_from_id(id_muni, muni_list_table) + # Return the municipality names + vector$municipality +} + +#' @rdname municipality_vector_from_id +#' @export +province_name_from_id <- function(id_muni, muni_list_table=anexo_municipios) { + vector <- municipality_vector_from_id(id_muni, muni_list_table) + # Return the province names + vector$province +} + +#' @rdname municipality_vector_from_id +#' @export +department_name_from_id <- function(id_muni, muni_list_table=anexo_municipios) { + vector <- municipality_vector_from_id(id_muni, muni_list_table) + # Return the department names + vector$department +} + +# This code produces a substantial lookup table for changes needed between +# our standard municipalities and gb2014. +muni_gb2014_conversion <- muni_id_lookup_table %>% + filter(muni_gb2014 != muni_anexo) %>% + select(1, 3, 2) %>% + mutate(recode = str_glue("mutate(municipality = recode(municipality, \"{muni_anexo}\"", + " = ", + "\"{muni_gb2014}\")) %>% ")) +# muni_gb2014_conversion$recode + +add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table){ + # Check if the dataframe has a column named "id_muni" + if (!"id_muni" %in% names(dataframe)) { + stop("The dataframe does not contain a column named 'id_muni'.") + } + # Check if the muni_table has column named "id_muni" and "muni_gb2014" + if (!"id_muni" %in% names(muni_table)) { + stop("The lookup does not contain a column named 'id_muni'.") + } + if (!"muni_gb2014" %in% names(muni_table)) { + stop("The lookup does not contain a column named 'muni_gb2014'.") + } + + lookup_table <- muni_table %>% + dplyr::select(id_muni, muni_gb2014) %>% + dplyr::distinct() + + # Join the lookup table with the dataframe + dataframe <- dataframe %>% + dplyr::left_join(lookup_table, by = "id_muni") + + return(dataframe) +} + +# de %>% add_id_for_municipality() %>% +# add_muni_gb2014_from_id() %>% +# select(event_title, municipality, muni_gb2014) %>% +# filter(municipality != muni_gb2014) +# de %>% add_id_for_municipality() %>% +# add_muni_gb2014_from_id() %>% +# select(event_title, municipality, muni_gb2014) %>% +# filter(municipality != muni_gb2014) %>% +# distinct(municipality, muni_gb2014) + +muni_gb2014_lookup <- muni_id_lookup_table %>% + select(id_muni, muni_gb2014, department) %>% + rename(municipality = muni_gb2014) + +# id_for_municipality("Villa Ricardo Mugia - Icla", muni_list_table = muni_gb2014_lookup) +# add_id_for_municipality(all_municipalities_new_full, muni_table = muni_gb2014_lookup) +# + diff --git a/tests/testthat/test-id-for-municipality.R b/tests/testthat/test-id-for-municipality.R new file mode 100644 index 0000000..6fa695b --- /dev/null +++ b/tests/testthat/test-id-for-municipality.R @@ -0,0 +1,67 @@ +test_that("Testing id_for_municipality", { + expect_equal(id_for_municipality("La Paz"), "020101") + expect_equal(id_for_municipality("La Paz", "La Paz"), "020101") + expect_warning(id_for_municipality("La Paz", "Cochabamba"), "Municipality La Paz not found in department Cochabamba . Returning empty string.") + expect_equal(suppressWarnings(id_for_municipality("La Paz", "Cochabamba")), "") + expect_equal(id_for_municipality("Potosí", "Potosí"), "050101") + expect_equal(id_for_municipality("Potosi"), "050101") + expect_equal(suppressWarnings(id_for_municipality("San Ramón")), "071103") + expect_warning(id_for_municipality("San Ramon"), "Multiple municipalities found for San Ramon without department . Returning first ID found.") + expect_equal(id_for_municipality("San Ramón", "Santa Cruz"), "071103") + expect_equal(id_for_municipality("San Ramón", "Beni"), "080702") +}) + +test_that("Testing id_for_municipality_2", { + expect_equal(id_for_municipality_2("zudanez"), "010301") + expect_equal(id_for_municipality_2("villa montes"), "060303") + expect_equal(id_for_municipality_2("villamontes"), "060303") + expect_warning(id_for_municipality_2("San Ignacio"), "Multiple municipalities found for San Ignacio without department . Returning first ID found.") + expect_equal(suppressWarnings(id_for_municipality_2("San Ignacio")), "070301") + expect_equal(id_for_municipality_2("San Ignacio", "Beni"), "080501") +}) + +test_that("Testing municipality_vector_from_id", { + expect_equal(municipality_vector_from_id("020101"), list(municipality = "La Paz", province = "Murillo", department = "La Paz")) + expect_equal(municipality_vector_from_id("050101") %>% unlist %>% unname, c("Potosí", "Tomás Frías", "Potosí")) + expect_equal(municipality_vector_from_id("071103") %>% unlist %>% unname, c("San Ramón", "Ñuflo de Chaves", "Santa Cruz")) + expect_equal(municipality_vector_from_id("080702") %>% unlist %>% unname, c("San Ramón", "Mamoré", "Beni")) + expect_equal(municipality_vector_from_id("010301") %>% unlist %>% unname, c("Villa Zudáñez", "Zudáñez", "Chuquisaca")) + expect_equal(municipality_vector_from_id("060303") %>% unlist %>% unname, c("Villa Montes", "Gran Chaco", "Tarija")) + expect_equal(municipality_vector_from_id("070301") %>% unlist %>% unname, c("San Ignacio de Velasco", "Velasco", "Santa Cruz")) + expect_equal(municipality_vector_from_id("080501") %>% unlist %>% unname, c("San Ignacio de Moxos", "Moxos", "Beni")) +}) + +test_that("Testing municipality_name_from_id", { + expect_equal(municipality_name_from_id("020101"), "La Paz") + expect_equal(municipality_name_from_id("050101"), "Potosí") + expect_equal(municipality_name_from_id("071103"), "San Ramón") + expect_equal(municipality_name_from_id("080702"), "San Ramón") + expect_equal(municipality_name_from_id("010301"), "Villa Zudáñez") + expect_equal(municipality_name_from_id("060303"), "Villa Montes") + expect_equal(municipality_name_from_id("070301"), "San Ignacio de Velasco") + expect_equal(municipality_name_from_id("080501"), "San Ignacio de Moxos") +}) + +test_that("Testing province_name_from_id", { + expect_equal(province_name_from_id("020101"), "Murillo") + expect_equal(province_name_from_id("050101"), "Tomás Frías") + expect_equal(province_name_from_id("071103"), "Ñuflo de Chaves") + expect_equal(province_name_from_id("080702"), "Mamoré") + expect_equal(province_name_from_id("010301"), "Zudáñez") + expect_equal(province_name_from_id("060303"), "Gran Chaco") + expect_equal(province_name_from_id("070301"), "Velasco") + expect_equal(province_name_from_id("080501"), "Moxos") +}) + +test_that("Testing department_name_from_id", { + expect_equal(department_name_from_id("020101"), "La Paz") + expect_equal(department_name_from_id("050101"), "Potosí") + expect_equal(department_name_from_id("071103"), "Santa Cruz") + expect_equal(department_name_from_id("080702"), "Beni") + expect_equal(department_name_from_id("010301"), "Chuquisaca") + expect_equal(department_name_from_id("060303"), "Tarija") + expect_equal(department_name_from_id("070301"), "Santa Cruz") + expect_equal(department_name_from_id("080501"), "Beni") +}) + + From 18af619d3714acc0109d16ba8879a6b67be3bfc9 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 18:48:26 -0700 Subject: [PATCH 03/13] Variable creation --- R/id-for-municipality.R | 145 +++++----- R/muni-id-tables.R | 21 ++ data-raw/anexo_municipios_de_bolivia.csv | 341 +++++++++++++++++++++++ data-raw/muni_id_lookup_table.rds | Bin 0 -> 45969 bytes data/anexo_municipios.rda | Bin 0 -> 8091 bytes data/muni_gb2014_conversion.rda | Bin 0 -> 1737 bytes data/muni_gb2014_lookup.rda | Bin 0 -> 3026 bytes data/muni_id_lookup_table.rda | Bin 0 -> 5833 bytes 8 files changed, 426 insertions(+), 81 deletions(-) create mode 100644 R/muni-id-tables.R create mode 100644 data-raw/anexo_municipios_de_bolivia.csv create mode 100644 data-raw/muni_id_lookup_table.rds create mode 100644 data/anexo_municipios.rda create mode 100644 data/muni_gb2014_conversion.rda create mode 100644 data/muni_gb2014_lookup.rda create mode 100644 data/muni_id_lookup_table.rda diff --git a/R/id-for-municipality.R b/R/id-for-municipality.R index 7148d38..e420c9c 100644 --- a/R/id-for-municipality.R +++ b/R/id-for-municipality.R @@ -1,6 +1,3 @@ -anexo_municipios <- readr::read_csv(here::here("data", "anexo_municipios_de_bolivia.csv")) -# anexo_municipios <- read_rds("data/anexo_municipios.rds") - #' Rename Columns in a Dataframe for Standardization #' #' This function renames specific columns in a dataframe to standardize their names. @@ -26,7 +23,7 @@ anexo_municipios <- readr::read_csv(here::here("data", "anexo_municipios_de_boli #' departamento = c("La Paz", "Cochabamba"), #' codigo123 = c(101, 102) #' ) -#' +#' #' # Rename columns #' renamed_df <- rename_anexo_columns(df) #' print(names(renamed_df)) # Should include "municipality", "province", "department", "cod.mun" @@ -47,35 +44,35 @@ rename_anexo_columns <- function(dataframe) { dataframe <- dataframe %>% dplyr::rename(department = departamento) } - + # Rename "codigo" columns to "cod.mun" without suffix dataframe <- dataframe %>% dplyr::rename_with(~ gsub("^codigo.*$", "cod.mun", .), .cols = dplyr::starts_with("codigo")) - + return(dataframe) } #' Get the ID of a municipality based on its name -#' -#' Returns the unique identifier for a municipality based on its name and +#' +#' Returns the unique identifier for a municipality based on its name and #' optionally the department. These identifiers are the codes used -#' in the Bolivian government databases, known as INE codes for the +#' in the Bolivian government databases, known as INE codes for the #' Instituto Nacional de Estadística. -#' +#' #' The function will warn the user if a municipality name without #' department corresponds to multiple municipalities. In this case, the first #' municipality found will be returned. (There are about a dozen such cases in Bolivia.) -#' +#' #' `id_for_municipality_2` is a version of the function that handles lookup #' tables with lists of municipalities. It is relies on `muni_id_lookup_table`. -#' +#' #' @param municipality_i Name of the municipality to search for. #' @param department_i Optional name of the department to filter by. #' @param muni_list_table A data frame containing the municipality list table. -#' +#' #' @return The unique identifier for the municipality as listed in the `code` = #' column of the `muni_list_table`. If no match is found, returns an empty string. -#' +#' #' @export #' @examples #' id_for_municipality("La Paz") # 020101 @@ -86,7 +83,7 @@ rename_anexo_columns <- function(dataframe) { #' id_for_municipality("San Ramón") # 071103 #' id_for_municipality("San Ramón", "Santa Cruz") # 071103 #' id_for_municipality("San Ramón", "Beni") # 080702 -#' +#' #' id_for_municipality_2("zudanez") # "010301" #' id_for_municipality_2("villa montes") # "060303" #' id_for_municipality_2("villamontes") # "060303" @@ -96,12 +93,12 @@ id_for_municipality <- function(municipality_i, department_i = "", muni_list_tab if (is.na(municipality_i)){ return(as.character(NA)) } - + # Rename columns if necessary if ("municipio" %in% names(muni_list_table) && !"municipality" %in% names(muni_list_table)) { muni_list_table <- rename_anexo_columns(muni_list_table) } - + # Ensure the first column is named "code" and formatted as character with leading zeros names(muni_list_table)[1] <- "code" # reformat first column as a character with leading zero @@ -109,54 +106,54 @@ id_for_municipality <- function(municipality_i, department_i = "", muni_list_tab muni_list_table <- muni_list_table %>% mutate(code = as.character(sprintf("%06d", code))) } - + # Filter by municipality - municipality_row <- muni_list_table %>% + municipality_row <- muni_list_table %>% dplyr::filter(str_equivalent(municipality, municipality_i)) # print((municipality_row)) - + if (nrow(municipality_row) == 0) { warning(paste("Municipality", municipality_i, "not found. Returning empty string.")) return("") } - + # Further filter by department if provided if (department_i != "") { - municipality_row <- municipality_row %>% + municipality_row <- municipality_row %>% dplyr::filter(str_equivalent(department, department_i)) if (nrow(municipality_row) == 0) { warning(paste("Municipality", municipality_i, "not found in department", department_i, ". Returning empty string.")) return("") } } - + # Handle multiple results if (nrow(municipality_row) > 1) { - warning(paste("Multiple municipalities found for", municipality_i, - if (department_i != "") paste("in department", department_i) else "without department", + warning(paste("Multiple municipalities found for", municipality_i, + if (department_i != "") paste("in department", department_i) else "without department", ". Returning first ID found.")) } - + return(unname(municipality_row$code[1])) } #' Add an unique identifier for municipality (id_muni) column to a dataset -#' -#' @param dataset A dataframe with a column containing the name of the +#' +#' @param dataset A dataframe with a column containing the name of the #' municipality, named `municipality`. #' @param id_variable_name The name of the new column to be created. Default is #' `id_muni`. #' @param muni_table A data frame containing the municipality list table. #' @param overwrite A boolean indicating whether to overwrite an existing #' column. -#' +#' #' @return A dataframe with a new column `id_muni` containing the unique #' identifier for the municipality, placed before the `municipality` column. -#' +#' #' @export -add_id_for_municipality <- function(dataset, +add_id_for_municipality <- function(dataset, id_variable_name = "id_muni", - muni_table = anexo_municipios, + muni_table = anexo_municipios, overwrite = FALSE){ if (!"municipality" %in% names(dataset)) { stop("The dataset does not contain the 'municipality' column.") @@ -167,7 +164,7 @@ add_id_for_municipality <- function(dataset, "Call add_id_for_event() with overwrite = TRUE to replace it.")) return(dataset) } - + # dataset[[id_variable_name]] <- vapply(dataset$municipality, function(x) id_for_municipality(x, "", muni_table), # FUN.VALUE = character(1)) if ("muni_list" %in% names(muni_table)) { @@ -181,14 +178,13 @@ add_id_for_municipality <- function(dataset, id_for_municipality(dataset$municipality[i], dataset$department[i], muni_table) }, FUN.VALUE = character(1)) } - - dataset <- dataset %>% + + dataset <- dataset %>% dplyr::relocate(!!rlang::sym(id_variable_name), .before = municipality) - + return(dataset) } -muni_id_lookup_table <- readr::read_rds(here::here("data", "muni_id_lookup_table.rds")) #' @rdname id_for_municipality #' @export @@ -196,25 +192,25 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t if (is.na(municipality_i)){ return(as.character(NA)) } - + assertthat::assert_that( is.character(municipality_i), is.character(department_i), - is.data.frame(muni_list_table), + is.data.frame(muni_list_table), "muni_list" %in% names(muni_list_table) ) - + # Filter by municipality municipality_row <- muni_list_table %>% rowwise() %>% dplyr::filter(str_equivalent_list(municipality_i, muni_list)) - + # Check if no rows match the municipality if (nrow(municipality_row) == 0) { warning(paste("Municipality", municipality_i, "not found. Returning empty string.")) return("") } - + # Further filter by department if provided if (department_i != "") { municipality_row <- municipality_row %>% @@ -224,14 +220,14 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t return("") } } - + # Handle multiple results if (nrow(municipality_row) > 1) { - warning(paste("Multiple municipalities found for", municipality_i, - if (department_i != "") paste("in department", department_i) else "without department", + warning(paste("Multiple municipalities found for", municipality_i, + if (department_i != "") paste("in department", department_i) else "without department", ". Returning first ID found.")) } - + # Return the first matching id_muni return(unname(municipality_row$id_muni[1])) } @@ -263,20 +259,20 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t #' province = c("Oropeza", "Oropeza", "Oropeza"), #' department = c("Chuquisaca", "Chuquisaca", "Chuquisaca") #' ) -#' +#' #' # Lookup municipality details #' ids <- c("010101", "010102", "010999") #' result <- municipality_from_id_muni(ids, anexo_municipios) #' print(result) -#' +#' #' @export municipality_vector_from_id <- function(id_muni, muni_list_table=anexo_municipios) { - + # Rename columns if necessary if ("municipio" %in% names(muni_list_table) && !"municipality" %in% names(muni_list_table)) { muni_list_table <- rename_anexo_columns(muni_list_table) } - + # Ensure the first column is named "code" and formatted as character with leading zeros names(muni_list_table)[1] <- "code" # reformat first column as a character with leading zero @@ -288,20 +284,20 @@ municipality_vector_from_id <- function(id_muni, muni_list_table=anexo_municipio if (is.numeric(id_muni)) { id_muni <- as.character(sprintf("%06d", id_muni)) } - + # Perform a lookup for each ID in the id_muni matched_rows <- muni_list_table[match(id_muni, muni_list_table$code), ] - + # Extract the required columns and handle missing matches municipality <- matched_rows$municipality province <- matched_rows$province department <- matched_rows$department - + # Replace missing values (rows not found) with NA municipality[is.na(matched_rows$code)] <- NA province[is.na(matched_rows$code)] <- NA department[is.na(matched_rows$code)] <- NA - + # Return the result as a list list( municipality = municipality, @@ -315,15 +311,15 @@ municipality_vector_from_id <- function(id_muni, muni_list_table=anexo_municipio #' from the unique identifier (ID) of a municipality. The ID is a code used #' in the Bolivian government databases, known as INE codes for the #' Instituto Nacional de Estadística. -#' +#' #' @param id_muni A character vector of municipality IDs to look up. #' @param muni_list_table A lookup dataframe containing municipality information. -#' +#' #' @return A string with the name of the municipality, province, or department. #' #' @rdname municipality_vector_from_id #' @export -#' +#' #' @examples #' municipality_name_from_id("020101") # "La Paz" #' municipality_name_from_id("050101") # "Potosí" @@ -368,16 +364,6 @@ department_name_from_id <- function(id_muni, muni_list_table=anexo_municipios) { vector$department } -# This code produces a substantial lookup table for changes needed between -# our standard municipalities and gb2014. -muni_gb2014_conversion <- muni_id_lookup_table %>% - filter(muni_gb2014 != muni_anexo) %>% - select(1, 3, 2) %>% - mutate(recode = str_glue("mutate(municipality = recode(municipality, \"{muni_anexo}\"", - " = ", - "\"{muni_gb2014}\")) %>% ")) -# muni_gb2014_conversion$recode - add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table){ # Check if the dataframe has a column named "id_muni" if (!"id_muni" %in% names(dataframe)) { @@ -390,33 +376,30 @@ add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table if (!"muni_gb2014" %in% names(muni_table)) { stop("The lookup does not contain a column named 'muni_gb2014'.") } - + lookup_table <- muni_table %>% dplyr::select(id_muni, muni_gb2014) %>% dplyr::distinct() - + # Join the lookup table with the dataframe dataframe <- dataframe %>% - dplyr::left_join(lookup_table, by = "id_muni") - + dplyr::left_join(lookup_table, by = "id_muni") + return(dataframe) } -# de %>% add_id_for_municipality() %>% -# add_muni_gb2014_from_id() %>% -# select(event_title, municipality, muni_gb2014) %>% +# de %>% add_id_for_municipality() %>% +# add_muni_gb2014_from_id() %>% +# select(event_title, municipality, muni_gb2014) %>% # filter(municipality != muni_gb2014) -# de %>% add_id_for_municipality() %>% -# add_muni_gb2014_from_id() %>% -# select(event_title, municipality, muni_gb2014) %>% +# de %>% add_id_for_municipality() %>% +# add_muni_gb2014_from_id() %>% +# select(event_title, municipality, muni_gb2014) %>% # filter(municipality != muni_gb2014) %>% # distinct(municipality, muni_gb2014) -muni_gb2014_lookup <- muni_id_lookup_table %>% - select(id_muni, muni_gb2014, department) %>% - rename(municipality = muni_gb2014) # id_for_municipality("Villa Ricardo Mugia - Icla", muni_list_table = muni_gb2014_lookup) # add_id_for_municipality(all_municipalities_new_full, muni_table = muni_gb2014_lookup) -# +# diff --git a/R/muni-id-tables.R b/R/muni-id-tables.R new file mode 100644 index 0000000..6d920a6 --- /dev/null +++ b/R/muni-id-tables.R @@ -0,0 +1,21 @@ +anexo_municipios <- readr::read_csv(here::here("data-raw", "anexo_municipios_de_bolivia.csv")) +usethis::use_data(anexo_municipios, overwrite = TRUE) + +muni_id_lookup_table <- readr::read_rds(here::here("data-raw", "muni_id_lookup_table.rds")) +usethis::use_data(muni_id_lookup_table, overwrite = TRUE) + +# This code produces a substantial lookup table for changes needed between +# our standard municipalities and gb2014. +muni_gb2014_conversion <- muni_id_lookup_table %>% + filter(muni_gb2014 != muni_anexo) %>% + select(1, 3, 2) %>% + mutate(recode = str_glue("mutate(municipality = recode(municipality, \"{muni_anexo}\"", + " = ", + "\"{muni_gb2014}\")) %>% ")) +# muni_gb2014_conversion$recode +usethis::use_data(muni_gb2014_conversion, overwrite = TRUE) + +muni_gb2014_lookup <- muni_id_lookup_table %>% + select(id_muni, muni_gb2014, department) %>% + rename(municipality = muni_gb2014) +usethis::use_data(muni_gb2014_lookup, overwrite = TRUE) diff --git a/data-raw/anexo_municipios_de_bolivia.csv b/data-raw/anexo_municipios_de_bolivia.csv new file mode 100644 index 0000000..201130e --- /dev/null +++ b/data-raw/anexo_municipios_de_bolivia.csv @@ -0,0 +1,341 @@ +"codigo_ine","municipio","provincia","departamento","superficie","poblacion","densidad","municipio_alt" +"010101","Sucre","Oropeza","Chuquisaca",1820,296125,162.71,NA +"010102","Yotala","Oropeza","Chuquisaca",452.9,9241,20.4,NA +"010103","Poroma","Oropeza","Chuquisaca",1395,13640,9.78,NA +"010201","Azurduy","Azurduy","Chuquisaca",1700,7861,4.62,NA +"010202","Tarvita","Azurduy","Chuquisaca",1334,16470,12.35,NA +"010301","Villa Zudáñez","Zudáñez","Chuquisaca",701.1,12687,18.1,NA +"010302","Presto","Zudáñez","Chuquisaca",1329,12023,9.05,NA +"010303","Villa Mojocoya","Zudáñez","Chuquisaca",1247,8971,7.19,NA +"010304","Icla","Zudáñez","Chuquisaca",846.3,8854,10.46,NA +"010401","Padilla","Tomina","Chuquisaca",1620,7542,4.66,NA +"010402","Tomina","Tomina","Chuquisaca",826.9,8341,10.09,NA +"010403","Sopachuy","Tomina","Chuquisaca",620.4,6886,11.1,NA +"010404","Villa Alcalá","Tomina","Chuquisaca",312.8,3752,11.99,NA +"010405","El Villar","Tomina","Chuquisaca",895.5,5636,6.29,NA +"010501","Monteagudo","Hernando Siles","Chuquisaca",3387,24487,7.23,NA +"010502","Huacareta","Hernando Siles","Chuquisaca",2962,7201,2.43,NA +"010601","Tarabuco","Yamparáez","Chuquisaca",1029,13251,12.88,NA +"010602","Yamparáez","Yamparáez","Chuquisaca",598.8,8537,14.26,NA +"010701","Camargo","Nor Cinti","Chuquisaca",1990,14712,7.39,NA +"010702","San Lucas","Nor Cinti","Chuquisaca",3872,26486,6.84,NA +"010703","Incahuasi","Nor Cinti","Chuquisaca",870,16311,18.75,NA +"010704","Villa Charcas","Nor Cinti","Chuquisaca",1000,13924,13.92,NA +"010801","Villa Serrano","Belisario Boeto","Chuquisaca",1713,8961,5.23,NA +"010901","Villa Abecia","Sud Cinti","Chuquisaca",707.3,5371,7.59,NA +"010902","Culpina","Sud Cinti","Chuquisaca",3910,14868,3.8,NA +"010903","Las Carreras","Sud Cinti","Chuquisaca",994.6,5007,5.03,NA +"011001","Villa Vaca Guzmán","Luis Calvo","Chuquisaca",3793,13196,3.48,"Muyupampa" +"011002","Huacaya","Luis Calvo","Chuquisaca",1186,2546,2.15,NA +"011003","Macharetí","Luis Calvo","Chuquisaca",7880,7245,0.92,NA +"020101","La Paz","Murillo","La Paz",2001,755732,377.68,NA +"020102","Palca","Murillo","La Paz",743.7,21641,29.1,NA +"020103","Mecapaca","Murillo","La Paz",533.1,20455,38.37,NA +"020104","Achocalla","Murillo","La Paz",196.2,46068,234.8,NA +"020105","El Alto","Murillo","La Paz",351.3,885035,2519.31,NA +"020201","Achacachi","Omasuyos","La Paz",700,47064,67.23,NA +"020202","Ancoraimes","Omasuyos","La Paz",329.5,16900,51.29,NA +"020203","Chua Cocani","Omasuyos","La Paz",17.5,8657,494.69,NA +"020204","Huarina","Omasuyos","La Paz",205,9258,45.16,NA +"020205","Santiago de Huata","Omasuyos","La Paz",125,5096,40.77,NA +"020206","Huatajata","Omasuyos","La Paz",31,7183,231.71,NA +"020301","Coro Coro","Pacajes","La Paz",1145,13395,11.7,NA +"020302","Caquiaviri","Pacajes","La Paz",1586,15464,9.75,NA +"020303","Calacoto","Pacajes","La Paz",3958,12057,3.05,NA +"020304","Comanche","Pacajes","La Paz",436.9,5201,11.9,NA +"020305","Charaña","Pacajes","La Paz",2925,4124,1.41,NA +"020306","Waldo Ballivián","Pacajes","La Paz",123.5,6557,53.09,NA +"020307","Nazacara de Pacajes","Pacajes","La Paz",19.2,3990,207.81,NA +"020308","Callapa","Pacajes","La Paz",1236,7965,6.44,NA +"020401","Puerto Acosta","Camacho","La Paz",260,13940,53.62,NA +"020402","Mocomoco","Camacho","La Paz",531.6,17653,33.21,NA +"020403","Puerto Carabuco","Camacho","La Paz",415,17248,41.56,NA +"020404","Humanata","Camacho","La Paz",450,5615,12.48,NA +"020405","Escoma","Camacho","La Paz",130,8810,67.77,NA +"020501","Chuma","Muñecas","La Paz",599.8,17671,29.46,NA +"020502","Ayata","Muñecas","La Paz",671.4,8957,13.34,NA +"020503","Aucapata","Muñecas","La Paz",243.1,6720,27.64,NA +"020601","Sorata","Larecaja","La Paz",2087,30020,14.38,NA +"020602","Guanay","Larecaja","La Paz",3965,16373,4.13,NA +"020603","Tacacoma","Larecaja","La Paz",826.9,9705,11.74,NA +"020604","Quiabaya","Larecaja","La Paz",133.6,4221,31.59,NA +"020605","Combaya","Larecaja","La Paz",99.5,3502,35.2,NA +"020606","Tipuani","Larecaja","La Paz",300.9,7640,25.39,NA +"020607","Mapiri","Larecaja","La Paz",1381,21805,15.79,NA +"020608","Teoponte","Larecaja","La Paz",1599,13469,8.42,NA +"020701","Apolo","Franz Tamayo","La Paz",13970,19047,1.36,NA +"020702","Pelechuco","Franz Tamayo","La Paz",2549,8993,3.53,NA +"020801","Viacha","Ingavi","La Paz",857.3,113453,132.34,NA +"020802","Guaqui","Ingavi","La Paz",191.6,8599,44.88,NA +"020803","Tiahuanaco","Ingavi","La Paz",352.2,13568,38.52,NA +"020804","Desaguadero","Ingavi","La Paz",91.3,7867,86.17,NA +"020805","San Andrés de Machaca","Ingavi","La Paz",1528,7832,5.13,NA +"020806","Jesús de Machaca","Ingavi","La Paz",970,16957,17.48,NA +"020807","Taraco","Ingavi","La Paz",110.2,7511,68.16,NA +"020901","Luribay","Loayza","La Paz",509,10581,20.79,NA +"020902","Sapahaqui","Loayza","La Paz",846.8,16420,19.39,NA +"020903","Yaco","Loayza","La Paz",599.1,12303,20.54,NA +"020904","Malla","Loayza","La Paz",329.7,4866,14.76,NA +"020905","Cairoma","Loayza","La Paz",543.8,13657,25.11,NA +"021001","Inquisivi","Inquisivi","La Paz",3277,18764,5.73,NA +"021002","Quime","Inquisivi","La Paz",878.5,11184,12.73,NA +"021003","Cajuata","Inquisivi","La Paz",971.1,15485,15.95,NA +"021004","Colquiri","Inquisivi","La Paz",1060,23456,22.13,NA +"021005","Ichoca","Inquisivi","La Paz",852,9536,11.19,NA +"021006","Licoma Pampa","Inquisivi","La Paz",150.1,7791,51.91,NA +"021101","Chulumani","Sud Yungas","La Paz",286.6,18278,63.78,NA +"021102","Irupana","Sud Yungas","La Paz",1389,23076,16.61,NA +"021103","Yanacachi","Sud Yungas","La Paz",579.8,7583,13.08,NA +"021104","Palos Blancos","Sud Yungas","La Paz",3605,26995,7.49,NA +"021105","La Asunta","Sud Yungas","La Paz",2832,45586,16.1,NA +"021201","Pucarani","Los Andes","La Paz",940.8,49701,52.83,NA +"021202","Laja","Los Andes","La Paz",690.4,38612,55.93,NA +"021203","Batallas","Los Andes","La Paz",993.9,20503,20.63,NA +"021204","Puerto Pérez","Los Andes","La Paz",126.8,7874,62.1,NA +"021301","Sica Sica","Aroma","La Paz",1742,33546,19.26,NA +"021302","Umala","Aroma","La Paz",860.4,9021,10.48,NA +"021303","Ayo Ayo","Aroma","La Paz",491.6,11251,22.89,NA +"021304","Calamarca","Aroma","La Paz",495.6,15279,30.83,NA +"021305","Patacamaya","Aroma","La Paz",570.9,25049,43.88,NA +"021306","Colquencha","Aroma","La Paz",305.3,12344,40.43,NA +"021307","Collana","Aroma","La Paz",125.6,5525,43.99,NA +"021401","Coroico","Nor Yungas","La Paz",952.1,27531,28.92,NA +"021402","Coripata","Nor Yungas","La Paz",346.2,23910,69.06,NA +"021501","Ixiamas","Iturralde","La Paz",37453,12487,0.33,NA +"021502","San Buenaventura","Iturralde","La Paz",2839,10115,3.56,NA +"021601","Charazani","Bautista Saavedra","La Paz",2592,15854,6.12,NA +"021602","Curva","Bautista Saavedra","La Paz",601.2,6423,10.68,NA +"021701","Copacabana","Manco Kapac","La Paz",177.1,17431,98.42,NA +"021702","San Pedro de Tiquina","Manco Kapac","La Paz",61.2,9097,148.64,NA +"021703","Tito Yupanqui","Manco Kapac","La Paz",14.9,7512,504.16,NA +"021801","San Pedro de Curahuara","Gualberto Villarroel","La Paz",733.3,9044,12.33,NA +"021802","Papel Pampa","Gualberto Villarroel","La Paz",914.1,6222,6.81,NA +"021803","Chacarilla","Gualberto Villarroel","La Paz",370,2031,5.49,NA +"021901","Santiago de Machaca","General José Manuel Pando","La Paz",1276,6766,5.3,NA +"021902","Catacora","General José Manuel Pando","La Paz",563.2,5326,9.46,NA +"022001","Caranavi","Caranavi","La Paz",2100,59034,28.11,NA +"022002","Alto Beni","Caranavi","La Paz",950,10499,11.05,NA +"030101","Cochabamba","Cercado","Cochabamba",289.3,661484,2286.5,NA +"030201","Aiquile","Campero","Cochabamba",2723,23000,8.45,NA +"030202","Pasorapa","Campero","Cochabamba",2389,6468,2.71,NA +"030203","Omereque","Campero","Cochabamba",759.3,6678,8.79,NA +"030301","Independencia","Ayopaya","Cochabamba",1514,21717,14.34,NA +"030302","Morochata","Ayopaya","Cochabamba",600,14598,24.33,NA +"030303","Cocapata","Ayopaya","Cochabamba",6800,19467,2.86,NA +"030401","Tarata","Esteban Arze","Cochabamba",338.4,11235,33.2,NA +"030402","Anzaldo","Esteban Arze","Cochabamba",646.6,7322,11.32,NA +"030403","Arbieto","Esteban Arze","Cochabamba",147.2,30454,206.89,NA +"030404","Sacabamba","Esteban Arze","Cochabamba",185.7,4953,26.67,NA +"030501","Arani","Arani","Cochabamba",216.3,11411,52.76,NA +"030502","Vacas","Arani","Cochabamba",360.9,8425,23.34,NA +"030601","Arque","Arque","Cochabamba",516.8,10635,20.58,NA +"030602","Tacopaya","Arque","Cochabamba",554.9,10549,19.01,NA +"030701","Capinota","Capinota","Cochabamba",542.9,19291,35.53,NA +"030702","Santiváñez","Capinota","Cochabamba",307.3,7868,25.6,NA +"030703","Sicaya","Capinota","Cochabamba",132.7,3949,29.76,NA +"030801","Cliza","Germán Jordán","Cochabamba",54.3,20877,384.48,NA +"030802","Toco","Germán Jordán","Cochabamba",63.8,7208,112.98,NA +"030803","Tolata","Germán Jordán","Cochabamba",84,7372,87.76,NA +"030901","Quillacollo","Quillacollo","Cochabamba",565.3,165830,293.35,NA +"030902","Sipe Sipe","Quillacollo","Cochabamba",480.5,55601,115.71,NA +"030903","Tiquipaya","Quillacollo","Cochabamba",344.4,61600,178.86,NA +"030904","Vinto","Quillacollo","Cochabamba",217.9,55773,255.96,NA +"030905","Colcapirhua","Quillacollo","Cochabamba",28.8,66235,2299.83,NA +"031001","Sacaba","Chapare","Cochabamba",701.8,218502,311.35,NA +"031002","Colomi","Chapare","Cochabamba",559.7,19318,34.51,NA +"031003","Villa Tunari","Chapare","Cochabamba",14561,95588,6.56,NA +"031101","Tapacarí","Tapacarí","Cochabamba",1651,24534,14.86,NA +"031201","Totora","Carrasco","Cochabamba",2157,14766,6.85,NA +"031202","Pojo","Carrasco","Cochabamba",2392,11840,4.95,NA +"031203","Pocona","Carrasco","Cochabamba",838.6,12216,14.57,NA +"031204","Chimoré","Carrasco","Cochabamba",2740,27374,9.99,NA +"031205","Puerto Villarroel","Carrasco","Cochabamba",2241,64345,28.71,NA +"031206","Entre Ríos","Carrasco","Cochabamba",2101,45520,21.67,NA +"031301","Mizque","Mizque","Cochabamba",1895,19846,10.47,NA +"031302","Vila Vila","Mizque","Cochabamba",601.6,5220,8.68,NA +"031303","Alalay","Mizque","Cochabamba",423.1,3461,8.18,NA +"031401","Punata","Punata","Cochabamba",85.9,34813,405.27,NA +"031402","Villa Rivero","Punata","Cochabamba",103,8551,83.02,NA +"031403","San Benito","Punata","Cochabamba",141.7,12924,91.21,NA +"031404","Tacachi","Punata","Cochabamba",12.4,1276,102.9,NA +"031405","Cuchumuela","Punata","Cochabamba",63.6,3818,60.03,NA +"031501","Bolívar","Bolívar","Cochabamba",724,8197,11.32,NA +"031601","Tiraque","Tiraque","Cochabamba",2650,18190,6.86,NA +"031602","Shinahota","Tiraque","Cochabamba",737.81,27067,36.69,NA +"040101","Oruro","Cercado","Oruro",276.2,297497,1077.11,NA +"040102","Caracollo","Cercado","Oruro",2364,23068,9.76,NA +"040103","El Choro","Cercado","Oruro",1119,10393,9.29,NA +"040104","Paria","Cercado","Oruro",1373,15675,11.42,NA +"040201","Challapata","Abaroa","Oruro",2586,35339,13.67,NA +"040202","Quillacas","Abaroa","Oruro",921.7,5105,5.54,NA +"040301","Corque","Carangas","Oruro",3380,16020,4.74,NA +"040302","Choquecota","Carangas","Oruro",849.9,2980,3.51,NA +"040401","Curahuara de Carangas","Sajama","Oruro",2866,6671,2.33,NA +"040402","Turco","Sajama","Oruro",4895,5277,1.08,NA +"040501","Huachacalla","Litoral","Oruro",20.8,3974,191.06,NA +"040502","Escara","Litoral","Oruro",1166,4194,3.6,NA +"040503","Cruz de Machacamarca","Litoral","Oruro",524.5,1511,2.88,NA +"040504","Yunguyo de Litoral","Litoral","Oruro",176.8,882,4.99,NA +"040505","Esmeralda","Litoral","Oruro",606.1,3883,6.41,NA +"040601","Poopó","Poopó","Oruro",704.2,9152,13,NA +"040602","Pazña","Poopó","Oruro",740,4220,5.7,NA +"040603","Antequera","Poopó","Oruro",283.9,3614,12.73,NA +"040701","Huanuni","Dalence","Oruro",553.1,20028,36.21,NA +"040702","Machacamarca","Dalence","Oruro",306.8,6096,19.87,NA +"040801","Salinas de Garci Mendoza","Ladislao Cabrera","Oruro",4924,15906,3.23,NA +"040802","Pampa Aullagas","Ladislao Cabrera","Oruro",1062,3180,2.99,NA +"040901","Sabaya","Sabaya","Oruro",3384,15387,4.55,NA +"040902","Coipasa","Sabaya","Oruro",204.2,1405,6.88,NA +"040903","Chipaya","Sabaya","Oruro",300.1,2366,7.88,NA +"041001","Toledo","Saucarí","Oruro",2928,12115,4.14,NA +"041101","Eucaliptus","Tomás Barrón","Oruro",333.8,5443,16.31,NA +"041201","Santiago de Andamarca","Sud Carangas","Oruro",2321,6300,2.71,NA +"041202","Belén de Andamarca","Sud Carangas","Oruro",1080,2996,2.77,NA +"041301","Totora","San Pedro de Totora","Oruro",1443,6570,4.55,NA +"041401","Santiago de Huari","Sebastián Pagador","Oruro",2407,13439,5.58,NA +"041501","La Rivera","Mejillones","Oruro",198.2,1266,6.39,NA +"041502","Todos Santos","Mejillones","Oruro",238.1,1132,4.75,NA +"041503","Carangas","Mejillones","Oruro",257.7,1130,4.38,NA +"041601","Huayllamarca","Nor Carangas","Oruro",876.7,5980,6.82,NA +"050101","Potosí","Tomás Frías","Potosí",1233,218336,177.08,NA +"050102","Tinguipaya","Tomás Frías","Potosí",1464,28829,19.69,NA +"050103","Yocalla","Tomás Frías","Potosí",880.7,11119,12.63,NA +"050104","Urmiri","Tomás Frías","Potosí",1304,3162,2.42,NA +"050201","Uncía","Rafael Bustillo","Potosí",1000,22673,22.67,NA +"050202","Chayanta","Rafael Bustillo","Potosí",614.5,16008,26.05,NA +"050203","Llallagua","Rafael Bustillo","Potosí",536,41571,77.56,NA +"050204","Chuquihuta","Rafael Bustillo","Potosí",150,8170,54.47,NA +"050301","Betanzos","Cornelio Saavedra","Potosí",1909,31772,16.64,NA +"050302","Chaquí","Cornelio Saavedra","Potosí",454.1,9262,20.4,NA +"050303","Tacobamba","Cornelio Saavedra","Potosí",833.9,14208,17.04,NA +"050401","Colquechaca","Chayanta","Potosí",800,16163,20.2,NA +"050402","Ravelo","Chayanta","Potosí",1241,16728,13.48,NA +"050403","Pocoata","Chayanta","Potosí",1192,32307,27.1,NA +"050404","Ocurí","Chayanta","Potosí",941.7,14367,15.26,NA +"050405","San Pedro de Macha","Chayanta","Potosí",842,20933,24.86,NA +"050501","San Pedro de Buena Vista","Charcas","Potosí",2170,27961,12.89,NA +"050502","Toro Toro","Charcas","Potosí",1176,10719,9.11,NA +"050601","Cotagaita","Nor Chichas","Potosí",6435,29070,4.52,NA +"050602","Vitichi","Nor Chichas","Potosí",1756,10102,5.75,NA +"050701","Sacaca","Alonso de Ibáñez","Potosí",892.5,17188,19.26,NA +"050702","Caripuyo","Alonso de Ibáñez","Potosí",518.1,8427,16.27,NA +"050801","Tupiza","Sud Chichas","Potosí",6204,45531,7.34,NA +"050802","Atocha","Sud Chichas","Potosí",2108,9364,4.44,NA +"050901","Colcha K","Nor Lípez","Potosí",15904,12638,0.79,NA +"050902","San Pedro de Quemes","Nor Lípez","Potosí",4403,1603,0.36,NA +"051001","San Pablo de Lípez","Sud Lípez","Potosí",15321,3136,0.2,NA +"051002","Mojinete","Sud Lípez","Potosí",407.2,1022,2.51,NA +"051003","San Antonio de Esmoruco","Sud Lípez","Potosí",2512,1941,0.77,NA +"051101","Puna","Linares","Potosí",1400,16350,11.68,NA +"051102","Caiza D","Linares","Potosí",1376,12891,9.37,NA +"051103","Ckochas","Linares","Potosí",2100,14301,6.81,NA +"051201","Uyuni","Quijarro","Potosí",7784,35118,4.51,NA +"051202","Tomave","Quijarro","Potosí",8239,7811,0.95,NA +"051203","Porco","Quijarro","Potosí",1149,14626,12.73,NA +"051301","Arampampa","General Bilbao","Potosí",424.7,3623,8.53,NA +"051302","Acasio","General Bilbao","Potosí",345.3,4434,12.84,NA +"051401","Llica","Daniel Campos","Potosí",5812,4150,0.71,NA +"051402","Tahua","Daniel Campos","Potosí",1105,1561,1.41,NA +"051501","Villazón","Modesto Omiste","Potosí",2469,49312,19.97,NA +"051601","San Agustín","Enrique Baldivieso","Potosí",2116,2119,1,NA +"060101","Tarija","Cercado","Tarija",2132,238942,112.07,NA +"060201","Padcaya","Arce","Tarija",4431,17783,4.01,NA +"060202","Bermejo","Arce","Tarija",381,36967,97.03,NA +"060301","Yacuiba","Gran Chaco","Tarija",3641,97577,26.8,NA +"060302","Caraparí","Gran Chaco","Tarija",3126,15650,5.01,NA +"060303","Villa Montes","Gran Chaco","Tarija",11784,46010,3.9,NA +"060401","Uriondo","José María Avilés","Tarija",801.6,15954,19.9,NA +"060402","Yunchará","José María Avilés","Tarija",1834,4763,2.6,NA +"060501","San Lorenzo","Méndez","Tarija",1969,30352,15.41,NA +"060502","El Puente","Méndez","Tarija",2057,9504,4.62,NA +"060601","Entre Ríos","O'Connor","Tarija",5033,20846,4.14,NA +"070101","Santa Cruz de la Sierra","Andrés Ibáñez","Santa Cruz",1269,1606671,1266.09,NA +"070102","Cotoca","Andrés Ibáñez","Santa Cruz",619.5,106292,171.58,NA +"070103","Porongo","Andrés Ibáñez","Santa Cruz",943.5,23016,24.39,NA +"070104","La Guardia","Andrés Ibáñez","Santa Cruz",953.2,147622,154.87,NA +"070105","El Torno","Andrés Ibáñez","Santa Cruz",959.5,55558,57.9,NA +"070201","Warnes","Warnes","Santa Cruz",1315,150803,114.68,NA +"070202","Okinawa Uno","Warnes","Santa Cruz",1042,10508,10.08,NA +"070301","San Ignacio de Velasco","Velasco","Santa Cruz",49102,67610,1.38,NA +"070302","San Miguel de Velasco","Velasco","Santa Cruz",9544,15177,1.59,NA +"070303","San Rafael de Velasco","Velasco","Santa Cruz",9731,8786,0.9,NA +"070401","Buena Vista","Ichilo","Santa Cruz",2250,13586,6.04,NA +"070402","San Carlos","Ichilo","Santa Cruz",1212,18998,15.67,NA +"070403","Villa Yapacaní","Ichilo","Santa Cruz",9514,57683,6.06,NA +"070404","San Juan de Yapacaní","Ichilo","Santa Cruz",1578,10206,6.47,NA +"070501","San José de Chiquitos","Chiquitos","Santa Cruz",19121,40961,2.14,NA +"070502","Pailón","Chiquitos","Santa Cruz",13726,54357,3.96,NA +"070503","Roboré","Chiquitos","Santa Cruz",7353,18701,2.54,NA +"070601","Portachuelo","Sara","Santa Cruz",1076,20709,19.25,NA +"070602","Santa Rosa del Sara","Sara","Santa Cruz",4114,17984,4.37,NA +"070603","Colpa Bélgica","Sara","Santa Cruz",291.5,6020,20.65,NA +"070701","Lagunillas","Cordillera","Santa Cruz",1122,5910,5.27,NA +"070702","Charagua","Cordillera","Santa Cruz",71360,39262,0.55,NA +"070703","Cabezas","Cordillera","Santa Cruz",5058,31160,6.16,NA +"070704","Cuevo","Cordillera","Santa Cruz",872.5,4953,5.68,NA +"070705","Gutiérrez","Cordillera","Santa Cruz",2871,15169,5.28,"Kereimba Iyambae" +"070706","Camiri","Cordillera","Santa Cruz",1036,32656,31.52,NA +"070707","Boyuibe","Cordillera","Santa Cruz",1660,5603,3.38,NA +"070801","Vallegrande","Vallegrande","Santa Cruz",3188,17172,5.39,NA +"070802","El Trigal","Vallegrande","Santa Cruz",398.5,2367,5.94,NA +"070803","Moro Moro","Vallegrande","Santa Cruz",673.9,2811,4.17,NA +"070804","Postrervalle","Vallegrande","Santa Cruz",1157,1796,1.55,NA +"070805","Pucará","Vallegrande","Santa Cruz",682.3,2009,2.94,NA +"070901","Samaipata","Florida","Santa Cruz",2188,11814,5.4,NA +"070902","Pampagrande","Florida","Santa Cruz",1429,9650,6.75,NA +"070903","Mairana","Florida","Santa Cruz",922.4,12732,13.8,NA +"070904","Quirusillas","Florida","Santa Cruz",286.6,3095,10.8,NA +"071001","Montero","Obispo Santistevan","Santa Cruz",315,127544,404.9,NA +"071002","General Saavedra","Obispo Santistevan","Santa Cruz",529.4,16043,30.3,NA +"071003","Mineros","Obispo Santistevan","Santa Cruz",420.1,22731,54.11,NA +"071004","Fernández Alonso","Obispo Santistevan","Santa Cruz",760.1,14625,19.24,NA +"071005","San Pedro","Obispo Santistevan","Santa Cruz",3081,15158,4.92,NA +"071101","Concepción","Ñuflo de Chaves","Santa Cruz",35109,30109,0.86,NA +"071102","San Javier","Ñuflo de Chaves","Santa Cruz",3381,14897,4.41,NA +"071103","San Ramón","Ñuflo de Chaves","Santa Cruz",492.3,6346,12.89,NA +"071104","San Julián","Ñuflo de Chaves","Santa Cruz",5726,44635,7.8,NA +"071105","San Antonio de Lomerío","Ñuflo de Chaves","Santa Cruz",2503,8427,3.37,NA +"071106","Cuatro Cañadas","Ñuflo de Chaves","Santa Cruz",4486,25260,5.63,NA +"071201","San Matías","Ángel Sandóval","Santa Cruz",27082,15336,0.57,NA +"071301","Comarapa","Caballero","Santa Cruz",2900,17132,5.91,NA +"071302","Saipina","Caballero","Santa Cruz",489.5,6057,12.37,NA +"071401","Puerto Suárez","Germán Busch","Santa Cruz",12982,17378,1.34,NA +"071402","Puerto Quijarro","Germán Busch","Santa Cruz",1450,17826,12.29,NA +"071403","El Carmen Rivero Tórrez","Germán Busch","Santa Cruz",11011,8731,0.79,NA +"071501","Ascensión de Guarayos","Guarayos","Santa Cruz",8674,34002,3.92,NA +"071502","Urubichá","Guarayos","Santa Cruz",10470,6528,0.62,NA +"071503","El Puente","Guarayos","Santa Cruz",6745,17214,2.55,NA +"080101","Trinidad","Cercado","Beni",2539,124357,48.98,NA +"080102","San Javier","Cercado","Beni",8173,7654,0.94,NA +"080201","Riberalta","Vaca Díez","Beni",9726,107141,11.02,NA +"080202","Guayaramerín","Vaca Díez","Beni",6502,40759,6.27,NA +"080301","Reyes","General José Ballivián","Beni",12642,11274,0.89,NA +"080302","San Borja","General José Ballivián","Beni",13489,45562,3.38,NA +"080303","Santa Rosa","General José Ballivián","Beni",12106,10910,0.9,NA +"080304","Rurrenabaque","General José Ballivián","Beni",2529,21018,8.31,NA +"080401","Santa Ana del Yacuma","Yacuma","Beni",20093,18102,0.9,NA +"080402","Exaltación","Yacuma","Beni",24973,7890,0.32,NA +"080501","San Ignacio de Moxos","Moxos","Beni",20011,21578,1.08,NA +"080601","Loreto","Marbán","Beni",5364,4263,0.79,NA +"080602","San Andrés","Marbán","Beni",9355,15635,1.67,NA +"080701","San Joaquín","Mamoré","Beni",8692,6851,0.79,NA +"080702","San Ramón","Mamoré","Beni",10079,5441,0.54,NA +"080703","Puerto Siles","Mamoré","Beni",2071,1095,0.53,NA +"080801","Magdalena","Iténez","Beni",13634,12769,0.94,NA +"080802","Baures","Iténez","Beni",17616,6564,0.37,NA +"080803","Huacaraje","Iténez","Beni",4464,4628,1.04,NA +"090101","Cobija","Nicolás Suárez","Pando",451.1,54386,120.56,NA +"090102","Porvenir","Nicolás Suárez","Pando",10967,8970,0.82,NA +"090103","Bolpebra","Nicolás Suárez","Pando",2592,2390,0.92,NA +"090104","Bella Flor","Nicolás Suárez","Pando",5793,3632,0.63,NA +"090201","Puerto Rico","Manuripi","Pando",5320,7217,1.36,NA +"090202","San Pedro","Manuripi","Pando",2636,3239,1.23,NA +"090203","Filadelfia","Manuripi","Pando",11886,7941,0.67,NA +"090301","Puerto Gonzalo Moreno","Madre de Dios","Pando",1293,12006,9.29,NA +"090302","San Lorenzo","Madre de Dios","Pando",3171,9203,2.9,NA +"090303","Sena","Madre de Dios","Pando",7634,10264,1.34,NA +"090401","Santa Rosa del Abuná","Abuná","Pando",3890,2855,0.73,NA +"090402","Ingavi","Abuná","Pando",5430,2584,0.48,NA +"090501","Nueva Esperanza","General Federico Román","Pando",3651,1390,0.38,NA +"090502","Villa Nueva","General Federico Román","Pando",2823,2500,0.89,NA +"090503","Santos Mercado","General Federico Román","Pando",6623,2184,0.33,NA diff --git a/data-raw/muni_id_lookup_table.rds b/data-raw/muni_id_lookup_table.rds new file mode 100644 index 0000000000000000000000000000000000000000..94d768815b809c8f99f0d776d2a0ae5d8a08f8b2 GIT binary patch literal 45969 zcmeHQ&vzWRksjOR{2(b=j$+5zm&0sMyNC7D4^otmLt0j(kTFA2%4#ou&6zgY@^G5z zVJjw2`B!}Od#gj9Z+qqc74KIK6i{E!P@-&0mXt{ztw9w~01AZyP=mqu-wTaKheGebsyNds`@pq-scxSgU*XZDL^V)U!Kc#L^>ZVEEpqw|Z*_=0tceBQ`Qf^*b zHZqr~+%lD0zGllU*UGIJDJvvpg{0gf-Yw#-5^uG}v$d~M?YF7ir?r&T%cr&v*RR=} zNST~S#rmLWlT%VLr=&P%)Ti*GUNAx=#g3Tptdtw3f5Kxaw}P%wie%c67M_)9M_PDR z=FMv?bCqhiZBo`k&`Q#TwGiQ1O)OJ=)~1Iz!4x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gma(wo5Vs>B~hARky5v_f3y=?8kEGF+@=ywG> zcp(`tXRGK#cP28U;3%Qqo2|mgO$)KjnX$Ip; zbj;6TX}~U_3n%CVOyTUQT8tX){C0YR_jPNnl4W5nFCNziQfgO!?TV=7{mu{DW;)6X zL1UW&{KP-4bUO6w+xOzC{ffiLW^Q~Q??D&_ZDW`;NH39o(DiFu1EBN z=fDx>jH+@YTWwbF=YaUOx^=v1Q`mKGNsT-kPAY#h*&igsG+bHIp=z!rCGJ+$#|rO@ z_c6MU>&po?a(kF0wd`$d>sb+Y8!Kb4;yC z`#c*afY$p8P|G}CA9`u-oz0w|+0<{->yL1<@M_5Q-DhUa?L>8|#gZ*ov$Tr&BoY75 z17fkLrU%Ai>id7fz98w|86RQ28J*U9=Z*{ADwDVGb07I+!IO`D%2h!4sz&Dr{Lc%U zj<0peUmko1x$A!-L1^-?ex8=DmwQ&aE@xU^n@9Q2qFLU1Q~IGYF8Z&?QTQlJV{I2tUQ%jr)e4cugcSZwQN0)P1iq9t4C=nSJU;f zHm!Muc9HzHZ2hw>KkYMUbB^v-^7%e6a&=ACb9(c5Z}{clEAO1&L&|?#7~pX9$yc%$ ztI6pU`QJVnfiAM(xEt^O9sl{^hkyQWE#tgql69c%<+ifHmxnmu`sAW~{&Iis#aDFR~0cr*RjXX;dihS^vN?a`O03zuoont%R3 D;_{?& literal 0 HcmV?d00001 diff --git a/data/anexo_municipios.rda b/data/anexo_municipios.rda new file mode 100644 index 0000000000000000000000000000000000000000..981ad9c8579c410a414c6c627bbaee940fb43171 GIT binary patch literal 8091 zcmaJ^byO5iv|e_X4ymOCC6?|6372jG>6Bc$q$I>;S#e2m>5?U+8(9gFT99s$MoLmZ zNk!rDJLjGA{(JY#%$fV$JKz1z{Bh5WsnZ%6;WvDkIqK@WLTw9kw zySM8rgV5+tQ!JbS>OoFGsYJ{SJQe8fBIQ2ycA9#^q*q0&;*ZP31c;-sv~=dQEQgL4 z3oukOprlYU-kB=E(s`)K0PX<5?fSn4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3dQU770u586RSig_f&jqthXF-BO&=Bm~qcN=a#? zDj&D5TKrn+yYwWPvPh0zJT@z_Yc>`RkrWFvOb}pZn{C0g*VcTUrl=<%IWJep_|`Ps a14G&3Nwk94RUiJf8>C-TRnvZw8T3EEmHYw# literal 0 HcmV?d00001 diff --git a/data/muni_gb2014_conversion.rda b/data/muni_gb2014_conversion.rda new file mode 100644 index 0000000000000000000000000000000000000000..ca5c0558a06bface49fe3c6b77fd249ae23a2084 GIT binary patch literal 1737 zcmV;)1~&OZT4*^jL0KkKS<2#wVE_jgf8787|MYTaf8#&@|NsC0|L{NnAR;Ib2mt^A z;0QlV&q^6a+J|ib0LTCk(1L`?pS00E|e0000D02!*OpwMUl00E#h zG6sME0MG+NKmY&-007VcGzLHb0MGy$XaE2J0MG!cX&{p%)6kk2qbcMXXqhx*X_IO* zP0+3>yk5KebA(;Ynfm)dlS0gMo%R@xX6msLSXDwlYVMvWY zWe`b#%)yJWPKJ&*KK*=Ib5ZwtnWs$CVjR&Z-E*s{6%tq0tAFG2El?D zfI>uwl_enq_C-1(m7G+SRbJYP`#$7Ik|dEP<#X?w=sfADlKFpz1BhJGGvd1t`aJ>J6>8_VXE1q1{Dk;YFmY?1{s)I zt%ef`SXVo=@{4RUW-<`Tt;rd)VGZgDe0tlRShU*eDx`IASf+QWIHz=NA)!w!^eH*Y z%?oF3*U{@%Yjmu-=M%dM<%lNdQ<}M^YNJMD67^VFdhNGpQoKqk6s(FXnMGvPMRKT= z4X5{ShWk|+a5y^4KEyQ%G0TuLrh2yy+Z5uprHBSHl^9JWS-pXb)I$>}ogFo2I!>sx zo{v~~gCSP7b9fSwom`g)n1^|Z0Pw103q>Lth@oVZ1f0>{hMKt)0VaSO1`H4bY1@@m z$WdN`ijSuqc~4^P>&t_~a$7sH@7gROIV_B&KDz{FUTHFN#Gl3&=HOyL(=KE%p0+NG zJQ(oFF-)qLCH>piD~G#xRDI-CX(N!iy(UNv1q~raT~vS%Eq2awpRnS42AEjKtYs-) z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lCbuPH;tv+MtgZ)#3AY+0pU<0Z-SmN=o+1 z@Vy zTd+TIQh>Q?g*q`F@S}gR!oZ0Mz4ws(>q17xp7|Oq@>d1-cADCe{&wA!tjan|>E&{C zx1w#o=^Vm9TRg4j%oU;ftTzb7SvT#J{vy%o&}<5uL`_~)VxBz_FS7Ig=Kdgo2$L^q z&AY^nL6e|B?&2>`$EQmNf~-+!J-@XAX)#n4TlE?DJo ze9&72R+AP~`R{5W;8ot9tj0D!V)c7>Wml^3wzK#IE?;QysVA6JZeepuBt=}!l~Vph zC5tqnF077pi~UZnQ&ZtDfB4EOQ7fgF7C#C_I_bHF5NAnFq1D#CIr#%#U+MDW9j(#f zOx>%J!B55|zfHDKM$|mT1$jaF5F@#~2ZUH5ddAcs;>LPx(ayHsZ z!W;Vls(`%!a{j5F-V#=wbB`Sy9{)oeAV}RiPAc_7(`%S*4&(M~M%ao11Up zIluB@IJc}}G4rIN=8Jc(9e-vZMnAzHi^Ogyn#X+=HrS8J>75{!*!0utG6)jmRchFA ztps*@I3s}mw^J;mklX{Evjcy~eH)O_Je)*W zLTU9BrP9rmeltyPS3(Y)x@4(-+tb+ijDV1=ofv^*Bl&wF4%#{hO3L$s<7_^&9PC`_3XPb%4<}-Rn6_D zbB_YJ|HUbliuY;#TX%|3v{-Am8Rv*Yw9I*f<`CCX>-Yy-_)8z}&`mgNFaC033N08L J*QQUC{tqjIzk2`x literal 0 HcmV?d00001 From 6086322e217fc7ab9447dd66c54161703cd0ae75 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 02:00:01 +0000 Subject: [PATCH 04/13] package def. s_equiv_list function --- R/id-for-municipality.R | 12 ++++++------ R/str-equivalent.R | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/R/id-for-municipality.R b/R/id-for-municipality.R index e420c9c..0c09b75 100644 --- a/R/id-for-municipality.R +++ b/R/id-for-municipality.R @@ -28,7 +28,7 @@ #' renamed_df <- rename_anexo_columns(df) #' print(names(renamed_df)) # Should include "municipality", "province", "department", "cod.mun" #' -#' @importFrom dplyr rename rename_with starts_with +#' @importFrom dplyr rename rename_with starts_with pull mutate rowwise #' @export rename_anexo_columns <- function(dataframe) { # Check if destination columns are missing and perform renaming accordingly @@ -102,9 +102,9 @@ id_for_municipality <- function(municipality_i, department_i = "", muni_list_tab # Ensure the first column is named "code" and formatted as character with leading zeros names(muni_list_table)[1] <- "code" # reformat first column as a character with leading zero - if (is.numeric(pull(muni_list_table,1))){ + if (is.numeric(dplyr::pull(muni_list_table,1))){ muni_list_table <- muni_list_table %>% - mutate(code = as.character(sprintf("%06d", code))) + dplyr::mutate(code = as.character(sprintf("%06d", code))) } # Filter by municipality @@ -202,7 +202,7 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t # Filter by municipality municipality_row <- muni_list_table %>% - rowwise() %>% + dplyr::rowwise() %>% dplyr::filter(str_equivalent_list(municipality_i, muni_list)) # Check if no rows match the municipality @@ -276,9 +276,9 @@ municipality_vector_from_id <- function(id_muni, muni_list_table=anexo_municipio # Ensure the first column is named "code" and formatted as character with leading zeros names(muni_list_table)[1] <- "code" # reformat first column as a character with leading zero - if (is.numeric(pull(muni_list_table,1))){ + if (is.numeric(dplyr::pull(muni_list_table,1))){ muni_list_table <- muni_list_table %>% - mutate(code = as.character(sprintf("%06d", code))) + dplyr::mutate(code = as.character(sprintf("%06d", code))) } # Check if id_muni is a character vector if (is.numeric(id_muni)) { diff --git a/R/str-equivalent.R b/R/str-equivalent.R index 3742b77..89839e7 100644 --- a/R/str-equivalent.R +++ b/R/str-equivalent.R @@ -20,3 +20,29 @@ str_equivalent <- function(x, y) { y <- stringi::stri_trans_general(y, "Latin-ASCII") stringr::str_equal(x, y, ignore_case = TRUE) } + +#' Check for Equivalent Strings in a List +#' +#' This function checks if any string in a list is equivalent to a target string, +#' considering case insensitivity, accent removal, whitespace trimming, and non-breaking space replacement. +#' +#' @param string A character string to compare. +#' @param string_list A character vector of potential matches. +#' +#' @return A logical value: \code{TRUE} if any string in the list is equivalent to the target string, +#' or \code{FALSE} otherwise. +#' +#' @details +#' The function uses \code{\link{str_equivalent}} to determine string equivalence and applies it +#' to each element of the list. +#' +#' @examples +#' str_equivalent_list("café", c("cafe", "tea", "coffee")) # Returns TRUE +#' str_equivalent_list("hello", c("world", "hi")) # Returns FALSE +#' +#' @seealso \code{\link{str_equivalent}} +#' @export +str_equivalent_list <- function(string, string_list) { + # Check if any member of string_list is equivalent to string using str_equivalent + any(sapply(string_list, function(x) str_equivalent(string, x))) +} \ No newline at end of file From a0106225b0f55f45e90b3c4475af79c52728ff0e Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 02:07:31 +0000 Subject: [PATCH 05/13] variable documentation --- R/aaa-data.R | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/R/aaa-data.R b/R/aaa-data.R index 9df26be..1c0de21 100644 --- a/R/aaa-data.R +++ b/R/aaa-data.R @@ -160,6 +160,85 @@ #' to "diciembre" "month.name.es" +#' Municipal Reference Table for Bolivia +#' +#' A reference table containing municipality information for Bolivia, +#' read from the official anexo of municipalities. +#' +#' @format A data frame with columns: +#' \describe{ +#' \item{codigo/cod.mun}{Municipal code (INE code)} +#' \item{municipio/municipality}{Municipality name} +#' \item{provincia/province}{Province name} +#' \item{departamento/department}{Department name} +#' } +#' +#' @details +#' This table contains the official list of municipalities in Bolivia +#' with their corresponding INE (Instituto Nacional de Estadística) codes, +#' provinces, and departments. The table is used for municipality lookup +#' and ID assignment functions. +"anexo_municipios" + +#' Municipality ID Lookup Table +#' +#' A comprehensive lookup table for municipality IDs and names in Bolivia, +#' including alternative municipality names and mappings. +#' +#' @format A data frame with columns: +#' \describe{ +#' \item{id_muni}{Municipal ID (INE code)} +#' \item{muni_list}{List of alternative municipality names} +#' \item{muni_anexo}{Standard municipality name from anexo} +#' \item{muni_gb2014}{Municipality name in GB2014 format} +#' \item{department}{Department name} +#' } +#' +#' @details +#' This table provides comprehensive municipality lookup functionality, +#' including alternative spellings and name variations. It supports +#' the id_for_municipality_2() function and other advanced municipality +#' matching operations. +"muni_id_lookup_table" + +#' Municipality Name Conversion Table for GB2014 Format +#' +#' A lookup table for converting between standard municipality names +#' and GB2014 format municipality names in Bolivia. +#' +#' @format A data frame with columns: +#' \describe{ +#' \item{id_muni}{Municipal ID (INE code)} +#' \item{muni_gb2014}{Municipality name in GB2014 format} +#' \item{muni_anexo}{Standard municipality name from anexo} +#' \item{recode}{R code string for recoding municipality names} +#' } +#' +#' @details +#' This table contains only municipalities where the GB2014 format name +#' differs from the standard anexo name. It includes generated R code +#' strings that can be used to perform the name conversions automatically. +"muni_gb2014_conversion" + +#' Municipality Lookup Table in GB2014 Format +#' +#' A simplified lookup table using GB2014 format municipality names +#' for municipality ID and department lookup. +#' +#' @format A data frame with columns: +#' \describe{ +#' \item{id_muni}{Municipal ID (INE code)} +#' \item{municipality}{Municipality name in GB2014 format} +#' \item{department}{Department name} +#' } +#' +#' @details +#' This table provides a streamlined lookup mechanism using GB2014 +#' format municipality names. It's derived from muni_id_lookup_table +#' and can be used when working with data that uses GB2014 naming +#' conventions. +"muni_gb2014_lookup" + # This list produced by colnames(deaths_aug24) %>% dput() # Needed for dplyr references to variables # See: https://www.r-bloggers.com/2019/08/no-visible-binding-for-global-variable/ @@ -228,7 +307,10 @@ utils::globalVariables( "date_text", "sr_text", "lev", - "standard_factoring_variables" + "standard_factoring_variables", + "muni_list", + "muni_anexo", + "muni_gb2014" ) ) From f76b97e0c0dd8b60d529ab23c9640fd94ffa8d81 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 19:08:43 -0700 Subject: [PATCH 06/13] documentation --- NAMESPACE | 12 +++++ man/add_id_for_municipality.Rd | 32 +++++++++++++ man/anexo_municipios.Rd | 29 ++++++++++++ man/id_for_municipality.Rd | 60 ++++++++++++++++++++++++ man/muni_gb2014_conversion.Rd | 28 +++++++++++ man/muni_gb2014_lookup.Rd | 28 +++++++++++ man/muni_id_lookup_table.Rd | 30 ++++++++++++ man/municipality_vector_from_id.Rd | 75 ++++++++++++++++++++++++++++++ man/rename_anexo_columns.Rd | 40 ++++++++++++++++ man/str_equivalent_list.Rd | 33 +++++++++++++ 10 files changed, 367 insertions(+) create mode 100644 man/add_id_for_municipality.Rd create mode 100644 man/anexo_municipios.Rd create mode 100644 man/id_for_municipality.Rd create mode 100644 man/muni_gb2014_conversion.Rd create mode 100644 man/muni_gb2014_lookup.Rd create mode 100644 man/muni_id_lookup_table.Rd create mode 100644 man/municipality_vector_from_id.Rd create mode 100644 man/rename_anexo_columns.Rd create mode 100644 man/str_equivalent_list.Rd diff --git a/NAMESPACE b/NAMESPACE index dcd4474..f00188d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(add_days_between) export(add_detailed_label) export(add_detailed_label_es) export(add_id_for_event) +export(add_id_for_municipality) export(add_id_for_president) export(add_nameline) export(add_nameline_es) @@ -30,6 +31,7 @@ export(combine_names) export(count_events_in_month) export(count_ongoing_events) export(count_range_by) +export(department_name_from_id) export(displayed_date_string) export(estimated_date) export(estimated_date_string) @@ -48,16 +50,22 @@ export(fully_annotate_es) export(generate_examples_with_results) export(gray_pal) export(id_for_event) +export(id_for_municipality) +export(id_for_municipality_2) export(id_for_president) export(muni_counts_by) export(muni_list_with_counts_by) +export(municipality_name_from_id) +export(municipality_vector_from_id) export(n_categorized_by) export(n_filter) export(n_municipality) export(n_responsibility_by) export(perp_pal) +export(province_name_from_id) export(quasilogical_as_binary) export(red_pal) +export(rename_anexo_columns) export(render_age) export(render_age_es) export(render_presidency) @@ -70,6 +78,7 @@ export(set_maximums) export(share_of_largest_n) export(standard_filter) export(str_equivalent) +export(str_equivalent_list) export(string_to_listcase) export(sv_pal) export(top_values_string) @@ -90,10 +99,13 @@ importFrom(dplyr,if_any) importFrom(dplyr,is.tbl) importFrom(dplyr,left_join) importFrom(dplyr,mutate) +importFrom(dplyr,pull) importFrom(dplyr,relocate) +importFrom(dplyr,rename) importFrom(dplyr,rename_with) importFrom(dplyr,rowwise) importFrom(dplyr,select) +importFrom(dplyr,starts_with) importFrom(dplyr,summarize) importFrom(dplyr,ungroup) importFrom(forcats,fct_collapse) diff --git a/man/add_id_for_municipality.Rd b/man/add_id_for_municipality.Rd new file mode 100644 index 0000000..f66ef83 --- /dev/null +++ b/man/add_id_for_municipality.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/id-for-municipality.R +\name{add_id_for_municipality} +\alias{add_id_for_municipality} +\title{Add an unique identifier for municipality (id_muni) column to a dataset} +\usage{ +add_id_for_municipality( + dataset, + id_variable_name = "id_muni", + muni_table = anexo_municipios, + overwrite = FALSE +) +} +\arguments{ +\item{dataset}{A dataframe with a column containing the name of the +municipality, named `municipality`.} + +\item{id_variable_name}{The name of the new column to be created. Default is +`id_muni`.} + +\item{muni_table}{A data frame containing the municipality list table.} + +\item{overwrite}{A boolean indicating whether to overwrite an existing +column.} +} +\value{ +A dataframe with a new column `id_muni` containing the unique + identifier for the municipality, placed before the `municipality` column. +} +\description{ +Add an unique identifier for municipality (id_muni) column to a dataset +} diff --git a/man/anexo_municipios.Rd b/man/anexo_municipios.Rd new file mode 100644 index 0000000..06e57a9 --- /dev/null +++ b/man/anexo_municipios.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-data.R +\docType{data} +\name{anexo_municipios} +\alias{anexo_municipios} +\title{Municipal Reference Table for Bolivia} +\format{ +A data frame with columns: +\describe{ + \item{codigo/cod.mun}{Municipal code (INE code)} + \item{municipio/municipality}{Municipality name} + \item{provincia/province}{Province name} + \item{departamento/department}{Department name} +} +} +\usage{ +anexo_municipios +} +\description{ +A reference table containing municipality information for Bolivia, +read from the official anexo of municipalities. +} +\details{ +This table contains the official list of municipalities in Bolivia +with their corresponding INE (Instituto Nacional de Estadística) codes, +provinces, and departments. The table is used for municipality lookup +and ID assignment functions. +} +\keyword{datasets} diff --git a/man/id_for_municipality.Rd b/man/id_for_municipality.Rd new file mode 100644 index 0000000..8a5f76f --- /dev/null +++ b/man/id_for_municipality.Rd @@ -0,0 +1,60 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/id-for-municipality.R +\name{id_for_municipality} +\alias{id_for_municipality} +\alias{id_for_municipality_2} +\title{Get the ID of a municipality based on its name} +\usage{ +id_for_municipality( + municipality_i, + department_i = "", + muni_list_table = anexo_municipios +) + +id_for_municipality_2( + municipality_i, + department_i = "", + muni_list_table = muni_id_lookup_table +) +} +\arguments{ +\item{municipality_i}{Name of the municipality to search for.} + +\item{department_i}{Optional name of the department to filter by.} + +\item{muni_list_table}{A data frame containing the municipality list table.} +} +\value{ +The unique identifier for the municipality as listed in the `code` = + column of the `muni_list_table`. If no match is found, returns an empty string. +} +\description{ +Returns the unique identifier for a municipality based on its name and +optionally the department. These identifiers are the codes used +in the Bolivian government databases, known as INE codes for the +Instituto Nacional de Estadística. +} +\details{ +The function will warn the user if a municipality name without +department corresponds to multiple municipalities. In this case, the first +municipality found will be returned. (There are about a dozen such cases in Bolivia.) + +`id_for_municipality_2` is a version of the function that handles lookup + tables with lists of municipalities. It is relies on `muni_id_lookup_table`. +} +\examples{ + id_for_municipality("La Paz") # 020101 + id_for_municipality("La Paz", "La Paz") # 020101 + id_for_municipality("La Paz", "Cochabamba") # empty string + id_for_municipality("Potosí", "Potosí") # 050101 + id_for_municipality("Potosi") # 050101 + id_for_municipality("San Ramón") # 071103 + id_for_municipality("San Ramón", "Santa Cruz") # 071103 + id_for_municipality("San Ramón", "Beni") # 080702 + + id_for_municipality_2("zudanez") # "010301" + id_for_municipality_2("villa montes") # "060303" + id_for_municipality_2("villamontes") # "060303" + id_for_municipality_2("San Ignacio") # "070301" + id_for_municipality_2("San Ignacio", "Beni") # "080501" +} diff --git a/man/muni_gb2014_conversion.Rd b/man/muni_gb2014_conversion.Rd new file mode 100644 index 0000000..df85d0c --- /dev/null +++ b/man/muni_gb2014_conversion.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-data.R +\docType{data} +\name{muni_gb2014_conversion} +\alias{muni_gb2014_conversion} +\title{Municipality Name Conversion Table for GB2014 Format} +\format{ +A data frame with columns: +\describe{ + \item{id_muni}{Municipal ID (INE code)} + \item{muni_gb2014}{Municipality name in GB2014 format} + \item{muni_anexo}{Standard municipality name from anexo} + \item{recode}{R code string for recoding municipality names} +} +} +\usage{ +muni_gb2014_conversion +} +\description{ +A lookup table for converting between standard municipality names +and GB2014 format municipality names in Bolivia. +} +\details{ +This table contains only municipalities where the GB2014 format name +differs from the standard anexo name. It includes generated R code +strings that can be used to perform the name conversions automatically. +} +\keyword{datasets} diff --git a/man/muni_gb2014_lookup.Rd b/man/muni_gb2014_lookup.Rd new file mode 100644 index 0000000..69e9ad9 --- /dev/null +++ b/man/muni_gb2014_lookup.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-data.R +\docType{data} +\name{muni_gb2014_lookup} +\alias{muni_gb2014_lookup} +\title{Municipality Lookup Table in GB2014 Format} +\format{ +A data frame with columns: +\describe{ + \item{id_muni}{Municipal ID (INE code)} + \item{municipality}{Municipality name in GB2014 format} + \item{department}{Department name} +} +} +\usage{ +muni_gb2014_lookup +} +\description{ +A simplified lookup table using GB2014 format municipality names +for municipality ID and department lookup. +} +\details{ +This table provides a streamlined lookup mechanism using GB2014 +format municipality names. It's derived from muni_id_lookup_table +and can be used when working with data that uses GB2014 naming +conventions. +} +\keyword{datasets} diff --git a/man/muni_id_lookup_table.Rd b/man/muni_id_lookup_table.Rd new file mode 100644 index 0000000..2db4e14 --- /dev/null +++ b/man/muni_id_lookup_table.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aaa-data.R +\docType{data} +\name{muni_id_lookup_table} +\alias{muni_id_lookup_table} +\title{Municipality ID Lookup Table} +\format{ +A data frame with columns: +\describe{ + \item{id_muni}{Municipal ID (INE code)} + \item{muni_list}{List of alternative municipality names} + \item{muni_anexo}{Standard municipality name from anexo} + \item{muni_gb2014}{Municipality name in GB2014 format} + \item{department}{Department name} +} +} +\usage{ +muni_id_lookup_table +} +\description{ +A comprehensive lookup table for municipality IDs and names in Bolivia, +including alternative municipality names and mappings. +} +\details{ +This table provides comprehensive municipality lookup functionality, +including alternative spellings and name variations. It supports +the id_for_municipality_2() function and other advanced municipality +matching operations. +} +\keyword{datasets} diff --git a/man/municipality_vector_from_id.Rd b/man/municipality_vector_from_id.Rd new file mode 100644 index 0000000..bceeb65 --- /dev/null +++ b/man/municipality_vector_from_id.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/id-for-municipality.R +\name{municipality_vector_from_id} +\alias{municipality_vector_from_id} +\alias{municipality_name_from_id} +\alias{province_name_from_id} +\alias{department_name_from_id} +\title{Get Municipality Details from ID Vector} +\usage{ +municipality_vector_from_id(id_muni, muni_list_table = anexo_municipios) + +municipality_name_from_id(id_muni, muni_list_table = anexo_municipios) + +province_name_from_id(id_muni, muni_list_table = anexo_municipios) + +department_name_from_id(id_muni, muni_list_table = anexo_municipios) +} +\arguments{ +\item{id_muni}{A character vector of municipality IDs to look up.} + +\item{muni_list_table}{A lookup dataframe containing municipality information.} +} +\value{ +A list with three components: + - `municipality`: A character vector of municipality names. + - `province`: A character vector of province names. + - `department`: A character vector of department names. + +A string with the name of the municipality, province, or department. +} +\description{ +This function looks up municipality details (municipality, province, and department) +from a list of municipality IDs in the given `muni_list_table`. +} +\details{ +The function performs a lookup by matching the `id_muni` with the `cod.mun` column in `muni_list_table`. +If an ID is not found, the corresponding entries in the output list will be `NA`. +} +\examples{ +library(dplyr) +# Example `muni_list_table` +anexo_municipios <- tibble::tibble( + cod.mun = c("010101", "010102", "010103"), + municipality = c("Sucre", "Yotala", "Poroma"), + province = c("Oropeza", "Oropeza", "Oropeza"), + department = c("Chuquisaca", "Chuquisaca", "Chuquisaca") +) + +# Lookup municipality details +ids <- c("010101", "010102", "010999") +result <- municipality_from_id_muni(ids, anexo_municipios) +print(result) + +municipality_name_from_id("020101") # "La Paz" +municipality_name_from_id("050101") # "Potosí" +municipality_name_from_id("071103") # "San Ramón" +municipality_name_from_id("080702") # "San Ramón" +municipality_name_from_id("010301") # "Villa Zudáñez" +province_name_from_id("020101") # "Murillo" +province_name_from_id("050101") # "Tomás Frías" +province_name_from_id("071103") # "Ñuflo de Chaves" +province_name_from_id("080702") # "Mamoré" +province_name_from_id("010301") # "Zudáñez" +province_name_from_id("060303") # "Gran Chaco" +province_name_from_id("070301") # "Velasco" +province_name_from_id("080501") # "Moxos" +department_name_from_id("020101") # "La Paz" +department_name_from_id("050101") # "Potosí" +department_name_from_id("071103") # "Santa Cruz" +department_name_from_id("080702") # "Beni" +department_name_from_id("010301") # "Chuquisaca" +department_name_from_id("060303") # "Tarija" +department_name_from_id("070301") # "Santa Cruz" +department_name_from_id("080501") # "Beni" +} diff --git a/man/rename_anexo_columns.Rd b/man/rename_anexo_columns.Rd new file mode 100644 index 0000000..4922d87 --- /dev/null +++ b/man/rename_anexo_columns.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/id-for-municipality.R +\name{rename_anexo_columns} +\alias{rename_anexo_columns} +\title{Rename Columns in a Dataframe for Standardization} +\usage{ +rename_anexo_columns(dataframe) +} +\arguments{ +\item{dataframe}{A dataframe containing the columns to be standardized.} +} +\value{ +A dataframe with standardized column names. +} +\description{ +This function renames specific columns in a dataframe to standardize their names. +It ensures that the columns `municipality`, `province`, and `department` are present, renaming existing columns +(`municipio`, `provincia`, `departamento`) if necessary. Additionally, it renames any column starting with `codigo` +to `cod.mun`. +} +\details{ +- The function checks for the presence of `municipality`, `province`, and `department`. + If these columns are missing, it renames `municipio`, `provincia`, and `departamento` to their English equivalents. +- Any column name starting with `codigo` is renamed to `cod.mun`. +} +\examples{ +library(dplyr) +# Example dataframe +df <- data.frame( + municipio = c("La Paz", "Cochabamba"), + provincia = c("Pedro Domingo Murillo", "Cercado"), + departamento = c("La Paz", "Cochabamba"), + codigo123 = c(101, 102) +) + +# Rename columns +renamed_df <- rename_anexo_columns(df) +print(names(renamed_df)) # Should include "municipality", "province", "department", "cod.mun" + +} diff --git a/man/str_equivalent_list.Rd b/man/str_equivalent_list.Rd new file mode 100644 index 0000000..9200bc5 --- /dev/null +++ b/man/str_equivalent_list.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/str-equivalent.R +\name{str_equivalent_list} +\alias{str_equivalent_list} +\title{Check for Equivalent Strings in a List} +\usage{ +str_equivalent_list(string, string_list) +} +\arguments{ +\item{string}{A character string to compare.} + +\item{string_list}{A character vector of potential matches.} +} +\value{ +A logical value: \code{TRUE} if any string in the list is equivalent to the target string, +or \code{FALSE} otherwise. +} +\description{ +This function checks if any string in a list is equivalent to a target string, +considering case insensitivity, accent removal, whitespace trimming, and non-breaking space replacement. +} +\details{ +The function uses \code{\link{str_equivalent}} to determine string equivalence and applies it +to each element of the list. +} +\examples{ +str_equivalent_list("café", c("cafe", "tea", "coffee")) # Returns TRUE +str_equivalent_list("hello", c("world", "hi")) # Returns FALSE + +} +\seealso{ +\code{\link{str_equivalent}} +} From 956d56c62bc9d176ecfec19eb8aa45101a698e2c Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 19:26:35 -0700 Subject: [PATCH 07/13] update documentation; move data-raw code --- R/id-for-municipality.R | 21 +++++++++++++++------ {R => data-raw}/muni-id-tables.R | 0 2 files changed, 15 insertions(+), 6 deletions(-) rename {R => data-raw}/muni-id-tables.R (100%) diff --git a/R/id-for-municipality.R b/R/id-for-municipality.R index 0c09b75..62d665a 100644 --- a/R/id-for-municipality.R +++ b/R/id-for-municipality.R @@ -151,6 +151,10 @@ id_for_municipality <- function(municipality_i, department_i = "", muni_list_tab #' identifier for the municipality, placed before the `municipality` column. #' #' @export +#' +#' @examples +#' id_for_municipality("Villa Ricardo Mugia - Icla", muni_list_table = muni_gb2014_lookup) +#' id_for_municipality_2("Villa Ricardo Mugia - Icla", "Chuquisaca") add_id_for_municipality <- function(dataset, id_variable_name = "id_muni", muni_table = anexo_municipios, @@ -364,6 +368,16 @@ department_name_from_id <- function(id_muni, muni_list_table=anexo_municipios) { vector$department } +#' Add Municipality GB2014 Code from ID +#' +#' This function adds a column `muni_gb2014` to a dataframe based on the `id_muni` column. +#' It uses a lookup table to map `id_muni` to `muni_gb2014`. +#' +#' @param dataframe A dataframe containing a column `id_muni`. +#' @param muni_table A lookup table containing `id_muni` and `muni_gb2014` columns. +#' @return A dataframe with an additional column `muni_gb2014` containing the corresponding GB2014 codes. +#' +#' @export add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table){ # Check if the dataframe has a column named "id_muni" if (!"id_muni" %in% names(dataframe)) { @@ -388,7 +402,7 @@ add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table return(dataframe) } -# de %>% add_id_for_municipality() %>% +# deaths_aug24 %>% add_id_for_municipality() %>% # add_muni_gb2014_from_id() %>% # select(event_title, municipality, muni_gb2014) %>% # filter(municipality != muni_gb2014) @@ -398,8 +412,3 @@ add_muni_gb2014_from_id <- function(dataframe, muni_table = muni_id_lookup_table # filter(municipality != muni_gb2014) %>% # distinct(municipality, muni_gb2014) - -# id_for_municipality("Villa Ricardo Mugia - Icla", muni_list_table = muni_gb2014_lookup) -# add_id_for_municipality(all_municipalities_new_full, muni_table = muni_gb2014_lookup) -# - diff --git a/R/muni-id-tables.R b/data-raw/muni-id-tables.R similarity index 100% rename from R/muni-id-tables.R rename to data-raw/muni-id-tables.R From ab0887d07b794e24a2cf50fb703dbebb524dc00e Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 02:27:28 +0000 Subject: [PATCH 08/13] second test file --- {R => data-raw}/muni-id-tables.R | 0 tests/testthat/test-id-for-municipality-2.R | 154 ++++++++++++++++++++ 2 files changed, 154 insertions(+) rename {R => data-raw}/muni-id-tables.R (100%) create mode 100644 tests/testthat/test-id-for-municipality-2.R diff --git a/R/muni-id-tables.R b/data-raw/muni-id-tables.R similarity index 100% rename from R/muni-id-tables.R rename to data-raw/muni-id-tables.R diff --git a/tests/testthat/test-id-for-municipality-2.R b/tests/testthat/test-id-for-municipality-2.R new file mode 100644 index 0000000..7e2bbfb --- /dev/null +++ b/tests/testthat/test-id-for-municipality-2.R @@ -0,0 +1,154 @@ +# Test file for municipality ID lookup functions +library(testthat) +library(dplyr) + +# Create test data based on the provided structure +test_anexo_municipios <- data.frame( + codigo = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), + municipio = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), + provincia = c("Oropeza", "Oropeza", "Oropeza", "Azurduy", "Azurduy", "Zudáñez", "Zudáñez", "Zudáñez"), + departamento = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), + stringsAsFactors = FALSE +) + +test_muni_id_lookup_table <- data.frame( + id_muni = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), + muni_gb2014 = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Zudañez", "Presto", "Mojocoya"), + muni_anexo = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), + department = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), + muni_list = I(list( + "Sucre", + "Yotala", + "Poroma", + "Azurduy", + "Tarvita", + c("Villa Zudáñez", "Zudañez"), + "Presto", + c("Villa Mojocoya", "Mojocoya") + )), + stringsAsFactors = FALSE +) + +test_that("id_for_municipality returns correct IDs for exact matches", { + expect_equal(id_for_municipality("Sucre", "", test_anexo_municipios), "010101") + expect_equal(id_for_municipality("Yotala", "", test_anexo_municipios), "010102") + expect_equal(id_for_municipality("Villa Zudáñez", "", test_anexo_municipios), "010301") +}) + +test_that("id_for_municipality handles department filtering correctly", { + expect_equal(id_for_municipality("Sucre", "Chuquisaca", test_anexo_municipios), "010101") + expect_warning( + result <- id_for_municipality("Sucre", "La Paz", test_anexo_municipios), + "Municipality Sucre not found in department La Paz" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality handles non-existent municipalities", { + expect_warning( + result <- id_for_municipality("NonExistent", "", test_anexo_municipios), + "Municipality NonExistent not found" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality handles NA input", { + result <- id_for_municipality(NA, "", test_anexo_municipios) + expect_true(is.na(result)) +}) + +test_that("id_for_municipality_2 returns correct IDs for exact matches", { + expect_equal(id_for_municipality_2("Sucre", "", test_muni_id_lookup_table), "010101") + expect_equal(id_for_municipality_2("Yotala", "", test_muni_id_lookup_table), "010102") + expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") +}) + +test_that("id_for_municipality_2 handles alternative names correctly", { + expect_equal(id_for_municipality_2("Zudañez", "", test_muni_id_lookup_table), "010301") + expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") + expect_equal(id_for_municipality_2("Mojocoya", "", test_muni_id_lookup_table), "010303") + expect_equal(id_for_municipality_2("Villa Mojocoya", "", test_muni_id_lookup_table), "010303") +}) + +test_that("id_for_municipality_2 handles department filtering correctly", { + expect_equal(id_for_municipality_2("Sucre", "Chuquisaca", test_muni_id_lookup_table), "010101") + expect_warning( + result <- id_for_municipality_2("Sucre", "La Paz", test_muni_id_lookup_table), + "Municipality Sucre not found in department La Paz" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality_2 handles non-existent municipalities", { + expect_warning( + result <- id_for_municipality_2("NonExistent", "", test_muni_id_lookup_table), + "Municipality NonExistent not found" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality_2 handles NA input", { + result <- id_for_municipality_2(NA, "", test_muni_id_lookup_table) + expect_true(is.na(result)) +}) + +test_that("id_for_municipality_2 validates input parameters", { + expect_error( + id_for_municipality_2(123, "", test_muni_id_lookup_table), + "municipality_i is not a character vector" + ) + expect_error( + id_for_municipality_2("Sucre", 123, test_muni_id_lookup_table), + "department_i is not a character vector" + ) + expect_error( + id_for_municipality_2("Sucre", "", "not_a_dataframe"), + "muni_list_table is not a data frame" + ) + + # Test missing muni_list column + bad_table <- test_muni_id_lookup_table + bad_table$muni_list <- NULL + expect_error( + id_for_municipality_2("Sucre", "", bad_table), + "muni_list not in names\\(muni_list_table\\)" + ) +}) + +test_that("Functions handle numeric codes correctly", { + # Test with numeric codes in anexo table + numeric_anexo <- test_anexo_municipios + numeric_anexo$codigo <- as.numeric(c(10101, 10102, 10103, 10201, 10202, 10301, 10302, 10303)) + + expect_equal(id_for_municipality("Sucre", "", numeric_anexo), "010101") + expect_equal(id_for_municipality("Yotala", "", numeric_anexo), "010102") +}) + +test_that("Functions handle case-insensitive matching through str_equivalent", { + # Assuming str_equivalent handles case-insensitive matching + # These tests may need adjustment based on actual str_equivalent behavior + skip_if_not(exists("str_equivalent"), "str_equivalent function not available") + + expect_equal(id_for_municipality("sucre", "", test_anexo_municipios), "010101") + expect_equal(id_for_municipality_2("sucre", "", test_muni_id_lookup_table), "010101") +}) + +test_that("Multiple municipality warning is generated when appropriate", { + # Create test data with duplicate municipality names in different departments + multi_muni_table <- rbind( + test_anexo_municipios, + data.frame( + codigo = "020101", + municipio = "Sucre", # Duplicate name + provincia = "Murillo", + departamento = "La Paz", + stringsAsFactors = FALSE + ) + ) + + expect_warning( + result <- id_for_municipality("Sucre", "", multi_muni_table), + "Multiple municipalities found for Sucre.*Returning first ID found" + ) + expect_equal(result, "010101") # Should return first match +}) \ No newline at end of file From c1459d7901437ed99742b0f96b2e77267a93320e Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Thu, 24 Jul 2025 19:31:53 -0700 Subject: [PATCH 09/13] consolidate tests --- tests/testthat/test-id-for-municipality-2.R | 154 -------------------- tests/testthat/test-id-for-municipality.R | 151 +++++++++++++++++++ 2 files changed, 151 insertions(+), 154 deletions(-) delete mode 100644 tests/testthat/test-id-for-municipality-2.R diff --git a/tests/testthat/test-id-for-municipality-2.R b/tests/testthat/test-id-for-municipality-2.R deleted file mode 100644 index 7e2bbfb..0000000 --- a/tests/testthat/test-id-for-municipality-2.R +++ /dev/null @@ -1,154 +0,0 @@ -# Test file for municipality ID lookup functions -library(testthat) -library(dplyr) - -# Create test data based on the provided structure -test_anexo_municipios <- data.frame( - codigo = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), - municipio = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), - provincia = c("Oropeza", "Oropeza", "Oropeza", "Azurduy", "Azurduy", "Zudáñez", "Zudáñez", "Zudáñez"), - departamento = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), - stringsAsFactors = FALSE -) - -test_muni_id_lookup_table <- data.frame( - id_muni = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), - muni_gb2014 = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Zudañez", "Presto", "Mojocoya"), - muni_anexo = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), - department = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), - muni_list = I(list( - "Sucre", - "Yotala", - "Poroma", - "Azurduy", - "Tarvita", - c("Villa Zudáñez", "Zudañez"), - "Presto", - c("Villa Mojocoya", "Mojocoya") - )), - stringsAsFactors = FALSE -) - -test_that("id_for_municipality returns correct IDs for exact matches", { - expect_equal(id_for_municipality("Sucre", "", test_anexo_municipios), "010101") - expect_equal(id_for_municipality("Yotala", "", test_anexo_municipios), "010102") - expect_equal(id_for_municipality("Villa Zudáñez", "", test_anexo_municipios), "010301") -}) - -test_that("id_for_municipality handles department filtering correctly", { - expect_equal(id_for_municipality("Sucre", "Chuquisaca", test_anexo_municipios), "010101") - expect_warning( - result <- id_for_municipality("Sucre", "La Paz", test_anexo_municipios), - "Municipality Sucre not found in department La Paz" - ) - expect_equal(result, "") -}) - -test_that("id_for_municipality handles non-existent municipalities", { - expect_warning( - result <- id_for_municipality("NonExistent", "", test_anexo_municipios), - "Municipality NonExistent not found" - ) - expect_equal(result, "") -}) - -test_that("id_for_municipality handles NA input", { - result <- id_for_municipality(NA, "", test_anexo_municipios) - expect_true(is.na(result)) -}) - -test_that("id_for_municipality_2 returns correct IDs for exact matches", { - expect_equal(id_for_municipality_2("Sucre", "", test_muni_id_lookup_table), "010101") - expect_equal(id_for_municipality_2("Yotala", "", test_muni_id_lookup_table), "010102") - expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") -}) - -test_that("id_for_municipality_2 handles alternative names correctly", { - expect_equal(id_for_municipality_2("Zudañez", "", test_muni_id_lookup_table), "010301") - expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") - expect_equal(id_for_municipality_2("Mojocoya", "", test_muni_id_lookup_table), "010303") - expect_equal(id_for_municipality_2("Villa Mojocoya", "", test_muni_id_lookup_table), "010303") -}) - -test_that("id_for_municipality_2 handles department filtering correctly", { - expect_equal(id_for_municipality_2("Sucre", "Chuquisaca", test_muni_id_lookup_table), "010101") - expect_warning( - result <- id_for_municipality_2("Sucre", "La Paz", test_muni_id_lookup_table), - "Municipality Sucre not found in department La Paz" - ) - expect_equal(result, "") -}) - -test_that("id_for_municipality_2 handles non-existent municipalities", { - expect_warning( - result <- id_for_municipality_2("NonExistent", "", test_muni_id_lookup_table), - "Municipality NonExistent not found" - ) - expect_equal(result, "") -}) - -test_that("id_for_municipality_2 handles NA input", { - result <- id_for_municipality_2(NA, "", test_muni_id_lookup_table) - expect_true(is.na(result)) -}) - -test_that("id_for_municipality_2 validates input parameters", { - expect_error( - id_for_municipality_2(123, "", test_muni_id_lookup_table), - "municipality_i is not a character vector" - ) - expect_error( - id_for_municipality_2("Sucre", 123, test_muni_id_lookup_table), - "department_i is not a character vector" - ) - expect_error( - id_for_municipality_2("Sucre", "", "not_a_dataframe"), - "muni_list_table is not a data frame" - ) - - # Test missing muni_list column - bad_table <- test_muni_id_lookup_table - bad_table$muni_list <- NULL - expect_error( - id_for_municipality_2("Sucre", "", bad_table), - "muni_list not in names\\(muni_list_table\\)" - ) -}) - -test_that("Functions handle numeric codes correctly", { - # Test with numeric codes in anexo table - numeric_anexo <- test_anexo_municipios - numeric_anexo$codigo <- as.numeric(c(10101, 10102, 10103, 10201, 10202, 10301, 10302, 10303)) - - expect_equal(id_for_municipality("Sucre", "", numeric_anexo), "010101") - expect_equal(id_for_municipality("Yotala", "", numeric_anexo), "010102") -}) - -test_that("Functions handle case-insensitive matching through str_equivalent", { - # Assuming str_equivalent handles case-insensitive matching - # These tests may need adjustment based on actual str_equivalent behavior - skip_if_not(exists("str_equivalent"), "str_equivalent function not available") - - expect_equal(id_for_municipality("sucre", "", test_anexo_municipios), "010101") - expect_equal(id_for_municipality_2("sucre", "", test_muni_id_lookup_table), "010101") -}) - -test_that("Multiple municipality warning is generated when appropriate", { - # Create test data with duplicate municipality names in different departments - multi_muni_table <- rbind( - test_anexo_municipios, - data.frame( - codigo = "020101", - municipio = "Sucre", # Duplicate name - provincia = "Murillo", - departamento = "La Paz", - stringsAsFactors = FALSE - ) - ) - - expect_warning( - result <- id_for_municipality("Sucre", "", multi_muni_table), - "Multiple municipalities found for Sucre.*Returning first ID found" - ) - expect_equal(result, "010101") # Should return first match -}) \ No newline at end of file diff --git a/tests/testthat/test-id-for-municipality.R b/tests/testthat/test-id-for-municipality.R index 6fa695b..9f1ca66 100644 --- a/tests/testthat/test-id-for-municipality.R +++ b/tests/testthat/test-id-for-municipality.R @@ -64,4 +64,155 @@ test_that("Testing department_name_from_id", { expect_equal(department_name_from_id("080501"), "Beni") }) +# Create test data based on the provided structure +test_anexo_municipios <- data.frame( + codigo = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), + municipio = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), + provincia = c("Oropeza", "Oropeza", "Oropeza", "Azurduy", "Azurduy", "Zudáñez", "Zudáñez", "Zudáñez"), + departamento = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), + stringsAsFactors = FALSE +) + +test_muni_id_lookup_table <- data.frame( + id_muni = c("010101", "010102", "010103", "010201", "010202", "010301", "010302", "010303"), + muni_gb2014 = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Zudañez", "Presto", "Mojocoya"), + muni_anexo = c("Sucre", "Yotala", "Poroma", "Azurduy", "Tarvita", "Villa Zudáñez", "Presto", "Villa Mojocoya"), + department = c("Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca", "Chuquisaca"), + muni_list = I(list( + "Sucre", + "Yotala", + "Poroma", + "Azurduy", + "Tarvita", + c("Villa Zudáñez", "Zudañez"), + "Presto", + c("Villa Mojocoya", "Mojocoya") + )), + stringsAsFactors = FALSE +) + +test_that("id_for_municipality returns correct IDs for exact matches", { + expect_equal(id_for_municipality("Sucre", "", test_anexo_municipios), "010101") + expect_equal(id_for_municipality("Yotala", "", test_anexo_municipios), "010102") + expect_equal(id_for_municipality("Villa Zudáñez", "", test_anexo_municipios), "010301") +}) + +test_that("id_for_municipality handles department filtering correctly", { + expect_equal(id_for_municipality("Sucre", "Chuquisaca", test_anexo_municipios), "010101") + expect_warning( + result <- id_for_municipality("Sucre", "La Paz", test_anexo_municipios), + "Municipality Sucre not found in department La Paz" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality handles non-existent municipalities", { + expect_warning( + result <- id_for_municipality("NonExistent", "", test_anexo_municipios), + "Municipality NonExistent not found" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality handles NA input", { + result <- id_for_municipality(NA, "", test_anexo_municipios) + expect_true(is.na(result)) +}) + +test_that("id_for_municipality_2 returns correct IDs for exact matches", { + expect_equal(id_for_municipality_2("Sucre", "", test_muni_id_lookup_table), "010101") + expect_equal(id_for_municipality_2("Yotala", "", test_muni_id_lookup_table), "010102") + expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") +}) + +test_that("id_for_municipality_2 handles alternative names correctly", { + expect_equal(id_for_municipality_2("Zudañez", "", test_muni_id_lookup_table), "010301") + expect_equal(id_for_municipality_2("Villa Zudáñez", "", test_muni_id_lookup_table), "010301") + expect_equal(id_for_municipality_2("Mojocoya", "", test_muni_id_lookup_table), "010303") + expect_equal(id_for_municipality_2("Villa Mojocoya", "", test_muni_id_lookup_table), "010303") +}) + +test_that("id_for_municipality_2 handles department filtering correctly", { + expect_equal(id_for_municipality_2("Sucre", "Chuquisaca", test_muni_id_lookup_table), "010101") + expect_warning( + result <- id_for_municipality_2("Sucre", "La Paz", test_muni_id_lookup_table), + "Municipality Sucre not found in department La Paz" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality_2 handles non-existent municipalities", { + expect_warning( + result <- id_for_municipality_2("NonExistent", "", test_muni_id_lookup_table), + "Municipality NonExistent not found" + ) + expect_equal(result, "") +}) + +test_that("id_for_municipality_2 handles NA input", { + result <- id_for_municipality_2(NA, "", test_muni_id_lookup_table) + expect_true(is.na(result)) +}) + +test_that("id_for_municipality_2 validates input parameters", { + expect_error( + id_for_municipality_2(123, "", test_muni_id_lookup_table), + "municipality_i is not a character vector" + ) + expect_error( + id_for_municipality_2("Sucre", 123, test_muni_id_lookup_table), + "department_i is not a character vector" + ) + expect_error( + id_for_municipality_2("Sucre", "", "not_a_dataframe"), + "muni_list_table is not a data frame" + ) + + # # Test missing muni_list column + # bad_table <- test_muni_id_lookup_table + # bad_table$muni_list <- NULL + # expect_error( + # id_for_municipality_2("Sucre", "", bad_table), + # "muni_list not in names\\(muni_list_table\\)" + # ) +}) + +test_that("Functions handle numeric codes correctly", { + # Test with numeric codes in anexo table + numeric_anexo <- test_anexo_municipios + numeric_anexo$codigo <- as.numeric(c(10101, 10102, 10103, 10201, 10202, 10301, 10302, 10303)) + + expect_equal(id_for_municipality("Sucre", "", numeric_anexo), "010101") + expect_equal(id_for_municipality("Yotala", "", numeric_anexo), "010102") +}) + +test_that("Functions handle case-insensitive matching through str_equivalent", { + # Assuming str_equivalent handles case-insensitive matching + # These tests may need adjustment based on actual str_equivalent behavior + skip_if_not(exists("str_equivalent"), "str_equivalent function not available") + + expect_equal(id_for_municipality("sucre", "", test_anexo_municipios), "010101") + expect_equal(id_for_municipality_2("sucre", "", test_muni_id_lookup_table), "010101") +}) + +test_that("Multiple municipality warning is generated when appropriate", { + # Create test data with duplicate municipality names in different departments + multi_muni_table <- rbind( + test_anexo_municipios, + data.frame( + codigo = "020101", + municipio = "Sucre", # Duplicate name + provincia = "Murillo", + departamento = "La Paz", + stringsAsFactors = FALSE + ) + ) + + expect_warning( + result <- id_for_municipality("Sucre", "", multi_muni_table), + "Multiple municipalities found for Sucre.*Returning first ID found" + ) + expect_equal(result, "010101") # Should return first match +}) + From fee47ab3ea24a829ea89a498177c2dcb1dfa51b1 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 22:42:19 -0700 Subject: [PATCH 10/13] fix examples and documentation --- NAMESPACE | 1 + R/aaa-data.R | 28 +++++++++++++++++++++------- R/id-for-municipality.R | 4 +--- man/add_id_for_municipality.Rd | 4 ++++ man/add_muni_gb2014_from_id.Rd | 20 ++++++++++++++++++++ man/anexo_municipios.Rd | 12 ++++++++---- man/muni_id_lookup_table.Rd | 7 +++++-- man/municipality_vector_from_id.Rd | 3 +-- man/rename_anexo_columns.Rd | 1 - 9 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 man/add_muni_gb2014_from_id.Rd diff --git a/NAMESPACE b/NAMESPACE index f00188d..d8d9695 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(add_detailed_label_es) export(add_id_for_event) export(add_id_for_municipality) export(add_id_for_president) +export(add_muni_gb2014_from_id) export(add_nameline) export(add_nameline_es) export(add_presidency_column) diff --git a/R/aaa-data.R b/R/aaa-data.R index 1c0de21..856bae4 100644 --- a/R/aaa-data.R +++ b/R/aaa-data.R @@ -167,10 +167,14 @@ #' #' @format A data frame with columns: #' \describe{ -#' \item{codigo/cod.mun}{Municipal code (INE code)} -#' \item{municipio/municipality}{Municipality name} -#' \item{provincia/province}{Province name} -#' \item{departamento/department}{Department name} +#' \item{codigo_ine}{Municipal code (INE code)} +#' \item{municipio}{Municipality name} +#' \item{provincia}{Province name} +#' \item{departamento}{Department name} +#' \item{superficie}{Area of the municipality in square kilometers} +#' \item{poblacion}{Population of the municipality} +#' \item{densidad}{Population density (people per square kilometer)} +#' \item{municipio_alt}{Alternative municipality name} #' } #' #' @details @@ -188,10 +192,13 @@ #' @format A data frame with columns: #' \describe{ #' \item{id_muni}{Municipal ID (INE code)} -#' \item{muni_list}{List of alternative municipality names} +#' \item{muni_gb2014}{Municipality name in GB2014 map format} #' \item{muni_anexo}{Standard municipality name from anexo} -#' \item{muni_gb2014}{Municipality name in GB2014 format} +#' \item{muni_ine}{Municipality name in INE table} +#' \item{muni_census}{Municipality name in census table} #' \item{department}{Department name} +#' \item{muni_list}{List of alternative municipality names} +#' \item{n_unique}{Number of unique names for the municipality} #' } #' #' @details @@ -310,7 +317,14 @@ utils::globalVariables( "standard_factoring_variables", "muni_list", "muni_anexo", - "muni_gb2014" + "muni_gb2014", + "anexo_municipios", + "muni_id_lookup_table", + "code", + "id_muni", + "municipio", + "provincia", + "departamento" ) ) diff --git a/R/id-for-municipality.R b/R/id-for-municipality.R index 62d665a..e610e5d 100644 --- a/R/id-for-municipality.R +++ b/R/id-for-municipality.R @@ -15,7 +15,6 @@ #' - Any column name starting with `codigo` is renamed to `cod.mun`. #' #' @examples -#' library(dplyr) #' # Example dataframe #' df <- data.frame( #' municipio = c("La Paz", "Cochabamba"), @@ -255,7 +254,6 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t #' If an ID is not found, the corresponding entries in the output list will be `NA`. #' #' @examples -#' library(dplyr) #' # Example `muni_list_table` #' anexo_municipios <- tibble::tibble( #' cod.mun = c("010101", "010102", "010103"), @@ -266,7 +264,7 @@ id_for_municipality_2 <- function(municipality_i, department_i = "", muni_list_t #' #' # Lookup municipality details #' ids <- c("010101", "010102", "010999") -#' result <- municipality_from_id_muni(ids, anexo_municipios) +#' result <- municipality_name_from_id(ids, anexo_municipios) #' print(result) #' #' @export diff --git a/man/add_id_for_municipality.Rd b/man/add_id_for_municipality.Rd index f66ef83..5903e5d 100644 --- a/man/add_id_for_municipality.Rd +++ b/man/add_id_for_municipality.Rd @@ -30,3 +30,7 @@ A dataframe with a new column `id_muni` containing the unique \description{ Add an unique identifier for municipality (id_muni) column to a dataset } +\examples{ +id_for_municipality("Villa Ricardo Mugia - Icla", muni_list_table = muni_gb2014_lookup) +id_for_municipality_2("Villa Ricardo Mugia - Icla", "Chuquisaca") +} diff --git a/man/add_muni_gb2014_from_id.Rd b/man/add_muni_gb2014_from_id.Rd new file mode 100644 index 0000000..890a04d --- /dev/null +++ b/man/add_muni_gb2014_from_id.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/id-for-municipality.R +\name{add_muni_gb2014_from_id} +\alias{add_muni_gb2014_from_id} +\title{Add Municipality GB2014 Code from ID} +\usage{ +add_muni_gb2014_from_id(dataframe, muni_table = muni_id_lookup_table) +} +\arguments{ +\item{dataframe}{A dataframe containing a column `id_muni`.} + +\item{muni_table}{A lookup table containing `id_muni` and `muni_gb2014` columns.} +} +\value{ +A dataframe with an additional column `muni_gb2014` containing the corresponding GB2014 codes. +} +\description{ +This function adds a column `muni_gb2014` to a dataframe based on the `id_muni` column. +It uses a lookup table to map `id_muni` to `muni_gb2014`. +} diff --git a/man/anexo_municipios.Rd b/man/anexo_municipios.Rd index 06e57a9..a7bcbe0 100644 --- a/man/anexo_municipios.Rd +++ b/man/anexo_municipios.Rd @@ -7,10 +7,14 @@ \format{ A data frame with columns: \describe{ - \item{codigo/cod.mun}{Municipal code (INE code)} - \item{municipio/municipality}{Municipality name} - \item{provincia/province}{Province name} - \item{departamento/department}{Department name} + \item{codigo_ine}{Municipal code (INE code)} + \item{municipio}{Municipality name} + \item{provincia}{Province name} + \item{departamento}{Department name} + \item{superficie}{Area of the municipality in square kilometers} + \item{poblacion}{Population of the municipality} + \item{densidad}{Population density (people per square kilometer)} + \item{municipio_alt}{Alternative municipality name} } } \usage{ diff --git a/man/muni_id_lookup_table.Rd b/man/muni_id_lookup_table.Rd index 2db4e14..5b7fb0c 100644 --- a/man/muni_id_lookup_table.Rd +++ b/man/muni_id_lookup_table.Rd @@ -8,10 +8,13 @@ A data frame with columns: \describe{ \item{id_muni}{Municipal ID (INE code)} - \item{muni_list}{List of alternative municipality names} + \item{muni_gb2014}{Municipality name in GB2014 map format} \item{muni_anexo}{Standard municipality name from anexo} - \item{muni_gb2014}{Municipality name in GB2014 format} + \item{muni_ine}{Municipality name in INE table} + \item{muni_census}{Municipality name in census table} \item{department}{Department name} + \item{muni_list}{List of alternative municipality names} + \item{n_unique}{Number of unique names for the municipality} } } \usage{ diff --git a/man/municipality_vector_from_id.Rd b/man/municipality_vector_from_id.Rd index bceeb65..dda97ce 100644 --- a/man/municipality_vector_from_id.Rd +++ b/man/municipality_vector_from_id.Rd @@ -37,7 +37,6 @@ The function performs a lookup by matching the `id_muni` with the `cod.mun` colu If an ID is not found, the corresponding entries in the output list will be `NA`. } \examples{ -library(dplyr) # Example `muni_list_table` anexo_municipios <- tibble::tibble( cod.mun = c("010101", "010102", "010103"), @@ -48,7 +47,7 @@ anexo_municipios <- tibble::tibble( # Lookup municipality details ids <- c("010101", "010102", "010999") -result <- municipality_from_id_muni(ids, anexo_municipios) +result <- municipality_name_from_id(ids, anexo_municipios) print(result) municipality_name_from_id("020101") # "La Paz" diff --git a/man/rename_anexo_columns.Rd b/man/rename_anexo_columns.Rd index 4922d87..a3411cf 100644 --- a/man/rename_anexo_columns.Rd +++ b/man/rename_anexo_columns.Rd @@ -24,7 +24,6 @@ to `cod.mun`. - Any column name starting with `codigo` is renamed to `cod.mun`. } \examples{ -library(dplyr) # Example dataframe df <- data.frame( municipio = c("La Paz", "Cochabamba"), From 8eb4957f7ba0b542aabb9dcdf52723579f4e6084 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:09:29 -0700 Subject: [PATCH 11/13] fix single translation error --- data-raw/presidency-name-table.csv | 58 ++++++++++++++--------------- data/presidency_name_table.rda | Bin 2217 -> 2244 bytes 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/data-raw/presidency-name-table.csv b/data-raw/presidency-name-table.csv index d952cdf..adbfb4e 100644 --- a/data-raw/presidency-name-table.csv +++ b/data-raw/presidency-name-table.csv @@ -1,29 +1,29 @@ -presidency,id_presidency,presidency_year,presidency_commonname,presidency_fullname,presidency_surnames,presidency_year_es,presidency_commonname_es,presidency_fullname_es,presidency_initials,presidency_initials_num,first_day,last_day -René Barrientos,p86,René Barrientos (1964-1969),René Barrientos,René Barrientos Ortuño,Barrientos Ortuño,René Barrientos (1964-1969),René Barrientos,René Barrientos Ortuño,RB,RB,1964-11-05,1966-08-06 -Luis Adolfo Siles Salinas,p87,Luis Adolfo Siles Salinas (1969),Luis Adolfo Siles Salinas,Luis Adolfo Siles Salinas,Siles Salinas,Luis Adolfo Siles Salinas (1969),Luis Adolfo Siles Salinas,Luis Adolfo Siles Salinas,LAS,LAS,1966-08-06,1969-04-27 -Alfredo Ovando Candía,p88,Alfredo Ovando (1969-1970),Alfredo Ovando,Alfredo Ovando Candía,Ovando Candía,Alfredo Ovando (1969-1970),Alfredo Ovando,Alfredo Ovando Candía,AO,AO,1969-04-27,1969-09-26 -Juan José Torres,p89,Juan José Torres (1970-1971),Juan José Torres,Juan José Torres González,Torres González,Juan José Torres (1970-1971),Juan José Torres,Juan José Torres González,JJT,JJT,1970-10-07,1971-08-21 -Hugo Banzer (1st),p90,Hugo Banzer (1971-1978),Hugo Banzer,Hugo Banzer Suárez,Banzer Suárez,Hugo Banzer (1971-1978),Hugo Banzer,Hugo Banzer Suárez,HB,HB 1,1971-08-22,1978-07-21 -Juan Pereda,p91,Juan Pereda (1978),Juan Pereda,Juan Pereda Asbún,Pereda Asbún,Juan Pereda (1978),Juan Pereda,Juan Pereda Asbún,JP,JP,1978-07-21,1978-11-24 -David Padilla (Chairman of the Military Junta),p92,David Padilla (1978-1979),David Padilla,David Padilla Arancibia,Padilla Arancibia,David Padilla (1978-1979),David Padilla,David Padilla Arancibia,DP,DP,1978-11-24,1979-08-08 -Wálter Guevara,p93,Walter Guevara (1979),Walter Guevara,Wálter Guevara Arze,Guevara Arze,Walter Guevara (1979),Walter Guevara,Wálter Guevara Arze,WG,WG,1979-08-08,1979-11-01 -Alberto Natusch,p94,Alberto Natusch (1979),Alberto Natusch,Alberto Natusch Busch,Natusch Busch,Alberto Natusch (1979),Alberto Natusch,Alberto Natusch Busch,AN,AN,1979-11-01,1979-11-16 -Lydia Gueiler Tejada,p95,Lidia Gueiler (1979-1980),Lidia Gueiler,Lidia Gueiler Tejada,Gueiler Tejada,Lidia Gueiler (1979-1980),Lidia Gueiler,Lidia Gueiler Tejada,LG,LG,1979-11-17,1980-07-18 -Luis García Meza Tejada (2nd),p96,Luis García Meza (1980-1981),Luis García Meza,Luis García Meza Tejada,García Meza Tejada,Luis García Meza (1980-1981),Luis García Meza,Luis García Meza Tejada,LGM,LGM,1980-07-18,1981-08-04 -Junta of Commanders of the Armed Forces 1981,p97,Junta of Commanders of the Armed Forces (1981),Military Junta (1981),Junta of Commanders of the Armed Forces of the Nation,Junta of Commanders of the Armed Forces of the Nation,Junta Militar de Comandantes de las Fuerzas Armadas (1981),Military Junta (1981),Junta Militar de Comandantes de las Fuerzas Armadas ,Junta,Junta 1981,1981-08-04,1981-09-04 -Celso Torrelio,p98,Celso Torrelio (1981-1982),Celso Torrelio,Celso Torrelio Villa,Torrelio Villa,Celso Torrelio (1981-1982),Celso Torrelio,Celso Torrelio Villa,CT,CT,1981-09-04,1982-07-19 -Junta of Commanders of the Armed Forces 1982,p99,Junta of Commanders of the Armed Forces (1982),Military Junta (1982),Junta of Commanders of the Armed Forces of the Nation,Junta of Commanders of the Armed Forces of the Nation,Junta Militar de Comandantes de las Fuerzas Armadas (1982),Military Junta (1982),Junta Militar de Comandantes de las Fuerzas Armadas ,Junta,Junta 1982,1982-07-19,1982-07-21 -Guido Vildoso,p100,Guido Vildoso (1982),Guido Vildoso,Guido Vildoso Calderón,Vildoso Calderón,Guido Vildoso (1982),Guido Vildoso,Guido Vildoso Calderón,GV,GV,1982-07-21,1982-10-10 -Hernán Siles Zuazo,p101,Hernán Siles Zuazo (1982-1985),Hernán Siles Zuazo,Hernán Siles Zuazo,Siles Zuazo,Hernán Siles Zuazo (1982-1985),Hernán Siles Zuazo,Hernán Siles Zuazo,HSZ,HSZ,1982-10-10,1985-08-06 -Víctor Paz Estenssoro,p102,Víctor Paz Estenssoro (1985-1989),Víctor Paz Estenssoro,Víctor Paz Estenssoro,Paz Estenssoro,Víctor Paz Estenssoro (1985-1989),Víctor Paz Estenssoro,Víctor Paz Estenssoro,VPE,VPE 2,1985-08-06,1989-08-06 -Jaime Paz Zamora,p103,Jaime Paz Zamora (1989-1993),Jaime Paz Zamora,Jaime Paz Zamora,Paz Zamora,Jaime Paz Zamora (1989-1993),Jaime Paz Zamora,Jaime Paz Zamora,JPZ,JPZ,1989-08-06,1993-08-06 -Gonzalo Sanchez de Lozada (1st),p104,Gonzalo Sánchez de Lozada (1993-1997),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,Sánchez de Lozada,Gonzalo Sánchez de Lozada (1993-1997),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,GSL,GSL 1,1993-08-06,1997-08-06 -Hugo Banzer (2nd),p105,Hugo Banzer (1997-2001),Hugo Banzer,Hugo Banzer Suárez,Banzer Suárez,Hugo Banzer (1997-2001),Hugo Banzer,Hugo Banzer Suárez,HB,HB 2,1997-08-06,2001-08-07 -Jorge Quiroga,p106,Jorge Quiroga (2001-2002),Jorge Quiroga,Jorge Quiroga Ramírez,Quiroga Ramírez,Jorge Quiroga (2001-2002),Jorge Quiroga,Jorge Quiroga Ramírez,JQ,JQ,2001-08-07,2002-08-06 -Gonzalo Sanchez de Lozada (2nd),p107,Gonzalo Sánchez de Lozada (2002-2003),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,Sánchez de Lozada,Gonzalo Sánchez de Lozada (2002-2003),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,GSL,GSL 2,2002-08-06,2003-10-17 -Carlos Diego Mesa Gisbert,p108,Carlos Mesa (2003-2005),Carlos Mesa,Carlos Diego Mesa Gisbert,Mesa Gisbert,Carlos Mesa (2003-2005),Carlos Mesa,Carlos Diego Mesa Gisbert,CM,CM,2003-10-17,2005-06-09 -Eduardo Rodríguez,p109,Eduardo Rodríguez (2005-2006),Eduardo Rodríguez,Eduardo Rodríguez Veltzé,Rodríguez Veltzé,Eduardo Rodríguez (2005-2006),Eduardo Rodríguez,Eduardo Rodríguez Veltzé,ER,ER,2005-06-09,2006-01-22 -Evo Morales,p110,Evo Morales (2006-2019),Evo Morales,Juan Evo Morales Ayma,Morales Ayma,Evo Morales (2006-2019),Evo Morales,Juan Evo Morales Ayma,EM,EM,2006-01-22,2019-11-10 -Interim military government,p111,Interim military government (2019),Military government (2019),Interim military government,Interim military government,Gobierno interino militar (2019),Military government (2019),Gobierno interino militar,Mil,Mil,2019-11-10,2019-11-12 -Jeanine Áñez,p112,Jeanine Áñez (2019-2020),Jeanine Áñez,Jeanine Áñez Chávez,Áñez Chávez,Jeanine Áñez (2019-2020),Jeanine Áñez,Jeanine Áñez Chávez,JÁ,JÁ,2019-11-12,2020-11-08 -Luis Arce,p113,Luis Arce (2020- ),Luis Arce,Luis Alberto Arce Catacora,Arce Catacora,Luis Arce (2020- ),Luis Arce,Luis Alberto Arce Catacora,LA,LA,2020-11-08,2025-03-20 \ No newline at end of file +presidency,id_presidency,presidency_year,presidency_commonname,presidency_fullname,presidency_surnames,presidency_year_es,presidency_commonname_es,presidency_fullname_es,presidency_initials,presidency_initials_num,first_day,last_day +René Barrientos,p86,René Barrientos (1964-1969),René Barrientos,René Barrientos Ortuño,Barrientos Ortuño,René Barrientos (1964-1969),René Barrientos,René Barrientos Ortuño,RB,RB,1964-11-05,1966-08-06 +Luis Adolfo Siles Salinas,p87,Luis Adolfo Siles Salinas (1969),Luis Adolfo Siles Salinas,Luis Adolfo Siles Salinas,Siles Salinas,Luis Adolfo Siles Salinas (1969),Luis Adolfo Siles Salinas,Luis Adolfo Siles Salinas,LAS,LAS,1966-08-06,1969-04-27 +Alfredo Ovando Candía,p88,Alfredo Ovando (1969-1970),Alfredo Ovando,Alfredo Ovando Candía,Ovando Candía,Alfredo Ovando (1969-1970),Alfredo Ovando,Alfredo Ovando Candía,AO,AO,1969-04-27,1969-09-26 +Juan José Torres,p89,Juan José Torres (1970-1971),Juan José Torres,Juan José Torres González,Torres González,Juan José Torres (1970-1971),Juan José Torres,Juan José Torres González,JJT,JJT,1970-10-07,1971-08-21 +Hugo Banzer (1st),p90,Hugo Banzer (1971-1978),Hugo Banzer,Hugo Banzer Suárez,Banzer Suárez,Hugo Banzer (1971-1978),Hugo Banzer,Hugo Banzer Suárez,HB,HB 1,1971-08-22,1978-07-21 +Juan Pereda,p91,Juan Pereda (1978),Juan Pereda,Juan Pereda Asbún,Pereda Asbún,Juan Pereda (1978),Juan Pereda,Juan Pereda Asbún,JP,JP,1978-07-21,1978-11-24 +David Padilla (Chairman of the Military Junta),p92,David Padilla (1978-1979),David Padilla,David Padilla Arancibia,Padilla Arancibia,David Padilla (1978-1979),David Padilla,David Padilla Arancibia,DP,DP,1978-11-24,1979-08-08 +Wálter Guevara,p93,Walter Guevara (1979),Walter Guevara,Wálter Guevara Arze,Guevara Arze,Walter Guevara (1979),Walter Guevara,Wálter Guevara Arze,WG,WG,1979-08-08,1979-11-01 +Alberto Natusch,p94,Alberto Natusch (1979),Alberto Natusch,Alberto Natusch Busch,Natusch Busch,Alberto Natusch (1979),Alberto Natusch,Alberto Natusch Busch,AN,AN,1979-11-01,1979-11-16 +Lydia Gueiler Tejada,p95,Lidia Gueiler (1979-1980),Lidia Gueiler,Lidia Gueiler Tejada,Gueiler Tejada,Lidia Gueiler (1979-1980),Lidia Gueiler,Lidia Gueiler Tejada,LG,LG,1979-11-17,1980-07-18 +Luis García Meza Tejada (2nd),p96,Luis García Meza (1980-1981),Luis García Meza,Luis García Meza Tejada,García Meza Tejada,Luis García Meza (1980-1981),Luis García Meza,Luis García Meza Tejada,LGM,LGM,1980-07-18,1981-08-04 +Junta of Commanders of the Armed Forces 1981,p97,Junta of Commanders of the Armed Forces (1981),Military Junta (1981),Junta of Commanders of the Armed Forces of the Nation,Junta of Commanders of the Armed Forces of the Nation,Junta Militar de Comandantes de las Fuerzas Armadas (1981),Military Junta (1981),Junta Militar de Comandantes de las Fuerzas Armadas ,Junta,Junta 1981,1981-08-04,1981-09-04 +Celso Torrelio,p98,Celso Torrelio (1981-1982),Celso Torrelio,Celso Torrelio Villa,Torrelio Villa,Celso Torrelio (1981-1982),Celso Torrelio,Celso Torrelio Villa,CT,CT,1981-09-04,1982-07-19 +Junta of Commanders of the Armed Forces 1982,p99,Junta of Commanders of the Armed Forces (1982),Military Junta (1982),Junta of Commanders of the Armed Forces of the Nation,Junta of Commanders of the Armed Forces of the Nation,Junta Militar de Comandantes de las Fuerzas Armadas (1982),Military Junta (1982),Junta Militar de Comandantes de las Fuerzas Armadas ,Junta,Junta 1982,1982-07-19,1982-07-21 +Guido Vildoso,p100,Guido Vildoso (1982),Guido Vildoso,Guido Vildoso Calderón,Vildoso Calderón,Guido Vildoso (1982),Guido Vildoso,Guido Vildoso Calderón,GV,GV,1982-07-21,1982-10-10 +Hernán Siles Zuazo,p101,Hernán Siles Zuazo (1982-1985),Hernán Siles Zuazo,Hernán Siles Zuazo,Siles Zuazo,Hernán Siles Zuazo (1982-1985),Hernán Siles Zuazo,Hernán Siles Zuazo,HSZ,HSZ,1982-10-10,1985-08-06 +Víctor Paz Estenssoro,p102,Víctor Paz Estenssoro (1985-1989),Víctor Paz Estenssoro,Víctor Paz Estenssoro,Paz Estenssoro,Víctor Paz Estenssoro (1985-1989),Víctor Paz Estenssoro,Víctor Paz Estenssoro,VPE,VPE 2,1985-08-06,1989-08-06 +Jaime Paz Zamora,p103,Jaime Paz Zamora (1989-1993),Jaime Paz Zamora,Jaime Paz Zamora,Paz Zamora,Jaime Paz Zamora (1989-1993),Jaime Paz Zamora,Jaime Paz Zamora,JPZ,JPZ,1989-08-06,1993-08-06 +Gonzalo Sanchez de Lozada (1st),p104,Gonzalo Sánchez de Lozada (1993-1997),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,Sánchez de Lozada,Gonzalo Sánchez de Lozada (1993-1997),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,GSL,GSL 1,1993-08-06,1997-08-06 +Hugo Banzer (2nd),p105,Hugo Banzer (1997-2001),Hugo Banzer,Hugo Banzer Suárez,Banzer Suárez,Hugo Banzer (1997-2001),Hugo Banzer,Hugo Banzer Suárez,HB,HB 2,1997-08-06,2001-08-07 +Jorge Quiroga,p106,Jorge Quiroga (2001-2002),Jorge Quiroga,Jorge Quiroga Ramírez,Quiroga Ramírez,Jorge Quiroga (2001-2002),Jorge Quiroga,Jorge Quiroga Ramírez,JQ,JQ,2001-08-07,2002-08-06 +Gonzalo Sanchez de Lozada (2nd),p107,Gonzalo Sánchez de Lozada (2002-2003),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,Sánchez de Lozada,Gonzalo Sánchez de Lozada (2002-2003),Gonzalo Sánchez de Lozada,Gonzalo Sánchez de Lozada,GSL,GSL 2,2002-08-06,2003-10-17 +Carlos Diego Mesa Gisbert,p108,Carlos Mesa (2003-2005),Carlos Mesa,Carlos Diego Mesa Gisbert,Mesa Gisbert,Carlos Mesa (2003-2005),Carlos Mesa,Carlos Diego Mesa Gisbert,CM,CM,2003-10-17,2005-06-09 +Eduardo Rodríguez,p109,Eduardo Rodríguez (2005-2006),Eduardo Rodríguez,Eduardo Rodríguez Veltzé,Rodríguez Veltzé,Eduardo Rodríguez (2005-2006),Eduardo Rodríguez,Eduardo Rodríguez Veltzé,ER,ER,2005-06-09,2006-01-22 +Evo Morales,p110,Evo Morales (2006-2019),Evo Morales,Juan Evo Morales Ayma,Morales Ayma,Evo Morales (2006-2019),Evo Morales,Juan Evo Morales Ayma,EM,EM,2006-01-22,2019-11-10 +Interim military government,p111,Interim military government (2019),Military government (2019),Interim military government,Interim military government,Gobierno interino militar (2019),Gobierno interino militar (2019),Gobierno interino militar,Mil,Mil,2019-11-10,2019-11-12 +Jeanine Áñez,p112,Jeanine Áñez (2019-2020),Jeanine Áñez,Jeanine Áñez Chávez,Áñez Chávez,Jeanine Áñez (2019-2020),Jeanine Áñez,Jeanine Áñez Chávez,JÁ,JÁ,2019-11-12,2020-11-08 +Luis Arce,p113,Luis Arce (2020- ),Luis Arce,Luis Alberto Arce Catacora,Arce Catacora,Luis Arce (2020- ),Luis Arce,Luis Alberto Arce Catacora,LA,LA,2020-11-08,2025-03-20 diff --git a/data/presidency_name_table.rda b/data/presidency_name_table.rda index a9f4e76a667e7da22b8c711746f0ab2446284134..8d6bea45c97f5cee32434844bc3bcb8c0fdd46a7 100644 GIT binary patch literal 2244 zcmV;#2s`&eT4*^jL0KkKS#3fh!2kn z(J+7+14B(T9Me&g^+Wwo(lpZ}15*$*$iie`Ob}#b(?da%(HJ8`Kxkl?Oqd|k69AY3 zV2w1u0GI(ZG%+v$000QWFbLBVA%KHSOafpDf;7_r0$>Et(8Rz1001Khz#~jdh5(8} zDtR$a)jcPoo{v)#(qXDSCPUQF%^=XxqtqUu>NE^Zl+)A!puzw&0qO-w5G2GAHbQBs zwv#E~X+uCXH1!P{4^RNpL7>punms_!^qK=kOoDU>ATY?|>g|Rg2tjahiohZZAA+!U zEeGhV8;?Qu4K#DD`0oMGFoPo+XE4J`D3cZdBrB;^G^hYd0BVItjF3?+q#nrF>?lGO?s;T5 z>wpIU00039LdiLpLBa78j9h|DYL*z1_v*;)yG(WK>vj8%qg>XrTd&yp_&r?g#mvob z1A}iVv5Si=cJ4V9D@GBfnNemkH7uoJgGqyHQ${UrU7D2Cq_J5kR9hu1Zmhv|Eoj2_ zQd5#g9YQ!H5Tqhb^&(41lp-T!1VaGC5Ti-RMdc8Hu?YnfQdLT!QA&!ar72RBiV~G1 zqEMwJ6%j;0?RB|ys0=C zFYXn03fRxg?RhuSs@LSaFqIpMG#5)tq~WdBOH*-x;{jVRIA+KbQrK__GFuj<%}Zbv zm4-vU29j6^S+KU2($Q@!E>jsY6$~WBEJ`pfCdoG?kwYPgV6nLvO$wetpu}pUWK5*l zKkAQ`kaikVuyQ(zbXIez;&m78Gh)!q$j!*rqU?%NUfI=g^|zYc#)~s*U3Jizv0Jby^XDjXUE^C*X-iEew&1i1U`)d)sGg9!96c{r$d>EcdnefL`&P3G)va?H<=pmiUgd|M!c>^e#687>16 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DR!ZQ?cfWJrUA0Zo*R;FN!^l?Yb0(Sb;lf-N@Po^ zRVh+bxnskkcm(+P^pZ0ivnA8PuwpnQ+a@x4@@P4S&yzF9Iy%g$+qp~~(NpA+B1Lv< zC{I~a1#W{ew*`n7D$coY!0-Wl2YOFpX@rr+HYUO2lNJ&>No5w2lE3)QgY~ea#(j{ zKE!F@s^edHNkG*UCoItNSk$IA()P$tuF)gZ`$;GLu|I3`sB~;WRNx z$0imslN&UpFEhbMf@c|=!p$QYDl9mX#`MUU7aJ;H^s1}=>X!|&R*l6ux;;(K5ur4t z8)T1$SWG0TD8)9EvlN_hADp`*0jo5Z3Yp1-op)+@qYnkG8y8ow$!1KGOXCb!vqDE+ zu~|i?R#*cyWnB|cD;C>8>_k|0vy!4uOq6JP29R!$VJG;gp<- zzrY@U()ps~i*WBsra6>j86*n?WH?4qhx4v2b72KwL28Ahq*$~{R4P>|Nho#xRErDA zFc?Y99>kI4K5Z$Sm<*FSG&`8AJd9+Q8!;a`;h4l=sGezg7BrtESnAhz813PL>WZb* z*(y@&N>pq~V$$-(Yf?2Q`9gC;7bwwk3x zVUjm5nV=;=?Tp-qg rmbHMyXdhrL*tu**&_PSn^Q8+#@TFW*3c?kN|NbuIig2MIwP4i}5N-ZI From c5a788e0a94d7a85f5c204ba753ff406cc7ad247 Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:19:58 -0700 Subject: [PATCH 12/13] More options for examples and tests --- R/add-presidency-column.R | 3 +++ tests/testthat/test-add-presidency-column.R | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/R/add-presidency-column.R b/R/add-presidency-column.R index 9710f04..4180c34 100644 --- a/R/add-presidency-column.R +++ b/R/add-presidency-column.R @@ -93,6 +93,9 @@ add_presidency_column <- function(dataframe, variable, #' render_presidency("Gonzalo Sanchez de Lozada (2nd)", "id_presidency") # "p107" #' render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_surnames") #' render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_year_es") +#' render_presidency("p111", "presidency_commonname_es", source_var="id_presidency") +#' render_presidency("p111", "presidency_initials_num", source_var="id_presidency") +#' render_presidency("p111", "presidency_commonname", source_var="id_presidency") render_presidency <- function(value, dest_var, lookup_table = presidency_name_table, diff --git a/tests/testthat/test-add-presidency-column.R b/tests/testthat/test-add-presidency-column.R index 1b0e938..7d2e97a 100644 --- a/tests/testthat/test-add-presidency-column.R +++ b/tests/testthat/test-add-presidency-column.R @@ -28,4 +28,8 @@ test_that("Testing render_presidency", { expect_equal(render_presidency("Gonzalo Sanchez de Lozada (2nd)", "id_presidency"), "p107") expect_equal(render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_surnames"), "Sánchez de Lozada") expect_equal(render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_year_es"), "Gonzalo Sánchez de Lozada (2002-2003)") + + expect_equal(render_presidency("p111", "presidency_commonname_es", source_var="id_presidency"), "Gobierno interino militar (2019)") + expect_equal(render_presidency("p111", "presidency_initials_num", source_var="id_presidency"), "Mil") + expect_equal(render_presidency("p111", "presidency_commonname", source_var="id_presidency"), "Military government (2019)") }) From 7aa6831bc74f25c6c8602b025a051bcd60c950da Mon Sep 17 00:00:00 2001 From: CarwilB <54286746+CarwilB@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:21:12 -0700 Subject: [PATCH 13/13] documentation --- man/render_presidency.Rd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/man/render_presidency.Rd b/man/render_presidency.Rd index 7730bc8..d3b5874 100644 --- a/man/render_presidency.Rd +++ b/man/render_presidency.Rd @@ -35,4 +35,7 @@ render_presidency("Gonzalo Sanchez de Lozada (2nd)", "first_day") # "2002-08-06" render_presidency("Gonzalo Sanchez de Lozada (2nd)", "id_presidency") # "p107" render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_surnames") render_presidency("Gonzalo Sanchez de Lozada (2nd)", "presidency_year_es") +render_presidency("p111", "presidency_commonname_es", source_var="id_presidency") +render_presidency("p111", "presidency_initials_num", source_var="id_presidency") +render_presidency("p111", "presidency_commonname", source_var="id_presidency") }