#' Import and prepare BNVD data
#'
#' @import dplyr
download_bnvd <- function() {
cat("\nLes données de vente de pesticides par département sont téléchargées depuis data.gouv.fr:\nhttps://www.data.gouv.fr/fr/datasets/donnees-de-vente-de-pesticides-par-departement/\n\n")
download_bnvd_file <- function(url) {
old.timeout <- options()$timeout
options(timeout = 40000)
data <- suppressMessages(
readr::read_delim(url,
delim = ";",
locale = readr::locale(decimal_mark = ","),
progress = FALSE )
)
options(timeout = old.timeout)
return(data)
}
list(BNVD_2018_VENTE_SUBSTANCE_2008 =
"https://www.data.gouv.fr/fr/datasets/r/3b63d103-330e-41b0-babe-1a890631e214",
BNVD_2018_VENTE_SUBSTANCE_2009 =
"https://www.data.gouv.fr/fr/datasets/r/d08e5842-abd5-457e-8eab-d94c9e4a6214",
BNVD_2018_VENTE_SUBSTANCE_2010 =
"https://www.data.gouv.fr/fr/datasets/r/0cfa3bd8-c4bd-407b-8cef-9f8498ccae4a",
BNVD_2018_VENTE_SUBSTANCE_2011 =
"https://www.data.gouv.fr/fr/datasets/r/6fef8cf7-e2f9-4089-b4ce-12a62572334d",
BNVD_2018_VENTE_SUBSTANCE_2012 =
"https://www.data.gouv.fr/fr/datasets/r/3b732693-8d19-43d5-8675-961bed6e607a",
BNVD_2018_VENTE_SUBSTANCE_2013 =
"https://www.data.gouv.fr/fr/datasets/r/64451253-ed0b-4262-a8fa-655f836089fe",
BNVD_2018_VENTE_SUBSTANCE_2014 =
"https://www.data.gouv.fr/fr/datasets/r/7e4d5850-5093-4529-92a7-a25966468b18",
BNVD_2018_VENTE_SUBSTANCE_2015 =
"https://www.data.gouv.fr/fr/datasets/r/dbd0bb7a-0234-4f46-85a1-7d0ff208dd6d",
BNVD_2018_VENTE_SUBSTANCE_2016 =
"https://www.data.gouv.fr/fr/datasets/r/30dd11ff-601d-4a74-b147-9f1b84a8d08b",
BNVD_2018_VENTE_SUBSTANCE_2017 =
"https://www.data.gouv.fr/fr/datasets/r/4a8764ee-4e38-4c92-9741-76c0cc88e96e"
) %>%
purrr::map(.x = ., .f = download_bnvd_file) %>%
bind_rows() %>%
mutate(quantite_substance = as.numeric(quantite_substance)) %>%
group_by(departement, annee, substance, classification) %>%
summarise(quantite = sum(quantite_substance) / 1e3) %>%
ungroup() %>%
mutate(departement =
case_when(departement == "TERRITOIRE DE BELFORT" ~
"TERRITOIRE-DE-BELFORT",
TRUE ~ departement),
classification = case_when(
classification %in% "T, T+, CMR" ~ "danger_sante",
classification %in% c("N Organique", "N minéral") ~ "danger_environnement",
classification %in% "Autre" ~ "autres_substances",
TRUE ~ classification
))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.