From 7c3e3f4dda06c9d4237a3f9a69a742e4d6c01142 Mon Sep 17 00:00:00 2001 From: Diego H Date: Fri, 2 Aug 2024 09:37:17 +0000 Subject: [PATCH] Update dictionaries --- NEWS.md | 3 +++ R/esp_dict.R | 28 ++++++++++++++++++++++++++++ tests/testthat/test-esp_dict.R | 19 ++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index c53806b0..3581ddc6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # mapSpain (development version) +- **SIANE 2024 Update**: Adapt functions to new databases. +- Improve dictionaries: `esp_dict_region_code()` and `esp_dict_translate()`. + # mapSpain 0.9.1 - Update actions and docs. diff --git a/R/esp_dict.R b/R/esp_dict.R index 96c0fdf8..6933cd99 100644 --- a/R/esp_dict.R +++ b/R/esp_dict.R @@ -61,6 +61,20 @@ #' esp_dict_region_code <- function(sourcevar, origin = "text", destination = "text") { + # Manually replace + sourcevar <- gsub("Ciudad de ceuta", "Ceuta", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("Ciudad de melilla", "Melilla", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta. cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + initsourcevar <- sourcevar validvars <- c("text", "nuts", "iso2", "codauto", "cpro") @@ -245,6 +259,20 @@ esp_dict_translate <- function(sourcevar, lang = "en", all = FALSE) { names_full[grep("name", dict$variable), c("key", "value")] ) + # Manually replace + sourcevar <- gsub("Ciudad de ceuta", "Ceuta", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("Ciudad de melilla", "Melilla", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta. cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + tokeys <- countrycode::countrycode(sourcevar, origin = "value", destination = "key", diff --git a/tests/testthat/test-esp_dict.R b/tests/testthat/test-esp_dict.R index 4a6b1d4f..05a3d493 100644 --- a/tests/testthat/test-esp_dict.R +++ b/tests/testthat/test-esp_dict.R @@ -16,7 +16,10 @@ test_that("Testing dict", { "Ciudad Autónoma de Ceuta", "Ciudad Autónoma de Melilla", "Región de Murcia", - "Principado de Asturias" + "Principado de Asturias", + "Ciudad de Ceuta", + "Ciudad de Melilla", + "Sta. Cruz de Tenerife" ), destination = "cpro" ) @@ -73,4 +76,18 @@ test_that("Testing dict", { expect_false(all(vals == test)) expect_true(all(vals == esp_dict_translate(test, "es"))) + expect_silent( + esp_dict_translate( + c( + "Ciudad Autónoma de Ceuta", + "Ciudad Autónoma de Melilla", + "Región de Murcia", + "Principado de Asturias", + "Ciudad de Ceuta", + "Ciudad de Melilla", + "Sta. Cruz de Tenerife" + ), + lang = "eu" + ) + ) })