Skip to content

Instantly share code, notes, and snippets.

@SimonCoulombe
Last active September 19, 2020 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonCoulombe/9a329052ac4cefd421febd8650ed84e2 to your computer and use it in GitHub Desktop.
Save SimonCoulombe/9a329052ac4cefd421febd8650ed84e2 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(aws.s3)
groupes <- c(
"Ensemble du Québec",
"01 Bas-Saint-Laurent",
"02 Saguenay-Lac-Saint-Jean",
"03 Capitale-Nationale",
"04 Mauricie et Centre-du-Québec",
"05 Estrie",
"06 Montréal",
"07 Outaouais",
"08 Abitibi-Témiscamingue",
"09 Côte-Nord",
"10 Nord-du-Québec",
"11 Gaspésie-Îles-de-la-Madeleine",
"12 Chaudière-Appalaches",
"13 Laval",
"14 Lanaudière",
"15 Laurentides",
"16 Montérégie",
"Inconnue",
"Hors Québec",
"Montréal et Laval",
"Ceinture de Montréal",
"Autres régions",
"0 à 9 ans",
"10 à 19 ans",
"20 à 29 ans",
"30 à 39 ans",
"40 à 49 ans",
"50 à 59 ans",
"60 à 69 ans",
"70 à 79 ans",
"80 à 89 ans",
"90 ans et +",
"Âge inconnu",
"Masculin",
"Féminin",
"Sexe inconnu"
)
types <- c(
"total",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region",
"region_montreal",
"region_montreal",
"region_montreal",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"groupe_age",
"sexe",
"sexe",
"sexe"
)
pouet <- list.files(
path = "~/cronjob/inspq-PL_DATE/",
pattern = ".csv$",
full.names = TRUE)
datetimes <- lubridate::ymd_hms(
paste0(
pouet %>% str_sub(
start=-19, end = -12),pouet %>%
str_sub(start=-10, end = -5) ))
latest_pl_date <- pouet[which.max(datetimes)]
my_colnames <- read_csv(latest_pl_date, skip =2)[,c(1,2:39)] %>%
janitor::clean_names() %>%
colnames
z <- map(seq(1:length(groupes)),~ {
temp <- read_csv(latest_pl_date,
skip =2,
col_types= cols(Mesure = col_character(),.default = col_double()))[,c(1,(38*(.x-1)+2):(38*.x+1))] %>%
janitor::clean_names()
colnames(temp) <- my_colnames
temp %>%
rename(date = mesure) %>%
mutate(groupe = groupes[.x],
type = types[.x],
date = lubridate::ymd(date)
) %>%
select(date, groupe, type, everything())
}
)
prepared_PL_DATE <- bind_rows(z)
write_csv(prepared_PL_DATE, "~/git/adhoc_prive/covid19_PNG/prepared_PL_DATE.csv")
put_object(file = "~/git/adhoc_prive/covid19_PNG/prepared_PL_DATE.csv",
object = paste0("covid19/", "prepared_PL_DATE.csv"),
bucket = "blogsimoncoulombe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment