## code to prepare `caracteristique` dataset goes here
library(conflicted)
library(data.table)
library(purrr)
library(dplyr)
library(lubridate)
caracteristique <- list.files("./data-raw/raw", pattern = "^caracteristiques", full.names = TRUE) %>%
map(fread, colClasses = "character", encoding = "Latin-1", na.strings = c("", "NA")) %>%
bind_rows() %>%
as_tibble() %>%
set_names(tolower) %>%
mutate(
an = case_when(
nchar(an) == 4 ~ an,
nchar(an) == 2 ~ paste0("20", an),
nchar(an) == 1 ~ paste0("200", an),
TRUE ~ NA_character_
),
across(c(an, mois, jour), as.numeric),
hrmn = case_when(
nchar(hrmn) == 5 ~ hrmn,
nchar(hrmn) == 4 ~ gsub(hrmn, pattern = "^(.{2})(.+)$", replacement = "\\1:\\2"),
nchar(hrmn) == 3 ~ gsub(paste0("0", hrmn), pattern = "^(.{2})(.+)$", replacement = "\\1:\\2"),
nchar(hrmn) == 2 ~ gsub(paste0("00", hrmn), pattern = "^(.{2})(.+)$", replacement = "\\1:\\2"),
nchar(hrmn) == 1 ~ gsub(paste0("000", hrmn), pattern = "^(.{2})(.+)$", replacement = "\\1:\\2"),
TRUE ~ NA_character_
),
heure_accident = ymd_hm(paste0(an, "-", mois, "-", jour, " ", hrmn)),
.after = hrmn,
lum = case_when(
lum %in% "1" ~ "Plein jour",
lum %in% "2" ~ "Crépuscule ou aube",
lum %in% "3" ~ "Nuit sans éclairage public",
lum %in% "4" ~ "Nuit avec éclairage public non allumé",
lum %in% "5" ~ "Nuit avec éclairage public allumé",
TRUE ~ NA_character_
),
agg = case_when(
agg %in% "1" ~ "Hors agglomération",
agg %in% "2" ~ "En agglomération",
TRUE ~ NA_character_
),
int = case_when(
int %in% "1" ~ "Hors intersection",
int %in% "2" ~ "Intersection en X",
int %in% "3" ~ "Intersection en T",
int %in% "4" ~ "Intersection en Y",
int %in% "5" ~ "Intersection à plus de 4 branches",
int %in% "6" ~ "Giratoire",
int %in% "7" ~ "Place",
int %in% "8" ~ "Passage à niveau",
int %in% "9" ~ "Autre intersection",
TRUE ~ NA_character_
),
atm = case_when(
atm %in% "1" ~ "Normale",
atm %in% "2" ~ "Pluie légère",
atm %in% "3" ~ "Pluie forte",
atm %in% "4" ~ "Neige - grêle",
atm %in% "5" ~ "Brouillard - fumée",
atm %in% "6" ~ "Vent fort - tempête",
atm %in% "7" ~ "Temps éblouissant",
atm %in% "8" ~ "Temps couvert",
atm %in% "9" ~ "Autre",
TRUE ~ NA_character_
),
col = case_when(
col %in% "1" ~ "Deux véhicules - frontale",
col %in% "2" ~ "Deux véhicules – par l’arrière",
col %in% "3" ~ "Deux véhicules – par le coté",
col %in% "4" ~ "Trois véhicules et plus – en chaîne",
col %in% "5" ~ "Trois véhicules et plus - collisions multiples",
col %in% "6" ~ "Autre collision",
col %in% "7" ~ "Sans collision",
TRUE ~ NA_character_
),
gps = case_when(
gps %in% "M" ~ "Métropole",
gps %in% "A" ~ "Antilles (Martinique ou Guadeloupe)",
gps %in% "G" ~ "Guyane",
gps %in% "R" ~ "Réunion",
gps %in% "Y" ~ "Mayotte",
TRUE ~ NA_character_
)
)
usethis::use_data(caracteristique, overwrite = TRUE, compress = "bzip2", ascii = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.