data-raw/vehicule_immatricule.R

## code to prepare `vehicule_immatricule` dataset goes here

library(conflicted)
library(data.table)
library(purrr)
library(dplyr)
library(tidyr)
library(stringr)

vehicule_immatricule <- list.files("./data-raw/raw", pattern = "^vehicules-immatricules-baac", full.names = TRUE) %>%
  map(fread, colClasses = "character", encoding = "UTF-8", na.strings = c("", "NA")) %>%
  bind_rows() %>%
  as_tibble() %>%
  set_names(
    c(
      "id_accident", "code_alpha", "an", "territoire", "type_accident_old",
      "cnit", "categorie_vehicule", "age_vehicule", "type_accident_new"
    )
  ) %>%
  mutate(
    across(everything(), \(x) na_if(x, "N/A")),
    an = as.numeric(an),
    id_accident = str_replace_all(string = id_accident, pattern = "\\D", replacement = ""),
    across(c(id_accident, age_vehicule), as.numeric)
  ) %>%
  unite(
    col = "type_accident", type_accident_old, type_accident_new,
    sep = "", remove = TRUE, na.rm = TRUE
  )

usethis::use_data(vehicule_immatricule, overwrite = TRUE, compress = "bzip2", ascii = FALSE)
ngsanogo/corpoaccident documentation built on Oct. 20, 2023, 2:27 a.m.