#' Import and prepare BNVD data
#'
#' @import dplyr
#'
import_bnvd <- function(file_list) {
download_bnvd <- function(url) {
tempCSV = tempfile(fileext = ".csv")
old.timeout <- options()$timeout
options(timeout = 40000)
utils::download.file(url, destfile = tempCSV,
method = "libcurl", cacheOK = TRUE)
options(timeout = old.timeout)
data <- data.table::fread(tempCSV)
file.remove(tempCSV)
return(data)
}
purrr::map(.x = file_list,
.f = download_bnvd) %>%
bind_rows() %>%
group_by(departement, annee, substance, cas) %>%
summarise(quantite = sum(quantite_substance)) %>%
ungroup() %>%
mutate(departement = case_when(departement == "TERRITOIRE DE BELFORT" ~
"TERRITOIRE-DE-BELFORT",
TRUE ~ departement))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.