Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
inst/doc
.DS_Store
13 changes: 13 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ 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_muni_gb2014_from_id)
export(add_nameline)
export(add_nameline_es)
export(add_presidency_column)
Expand All @@ -30,6 +32,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)
Expand All @@ -48,16 +51,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)
Expand All @@ -70,6 +79,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)
Expand All @@ -90,10 +100,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)
Expand Down
98 changes: 97 additions & 1 deletion R/aaa-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,92 @@
#' 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_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
#' 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_gb2014}{Municipality name in GB2014 map format}
#' \item{muni_anexo}{Standard municipality name from anexo}
#' \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
#' 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/
Expand Down Expand Up @@ -228,7 +314,17 @@ utils::globalVariables(
"date_text",
"sr_text",
"lev",
"standard_factoring_variables"
"standard_factoring_variables",
"muni_list",
"muni_anexo",
"muni_gb2014",
"anexo_municipios",
"muni_id_lookup_table",
"code",
"id_muni",
"municipio",
"provincia",
"departamento"
)
)

Expand Down
3 changes: 3 additions & 0 deletions R/add-presidency-column.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion R/data-cleaning.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading