Lacs_maj_compilation=function(){
  #LANCER CE SCRIPT A PARTIR DE CHEMIN_RACINE/
  
  if(!requireNamespace("dplyr", quietly = TRUE)){
    install.packages("dplyr")
  }
 library(dplyr)
  input_param=data.frame(Parametre=c('Caracteristiques',
                                     'Chlorophylle',
                                     'Transparence',
                                     'Physicochimie',
                                     'Multiparam',
                                     'Phytoplancton',
                                     'Zooplancton'),
                         rawCSV=c('./Donnees_brutes/Lacs_data_Caracteristiques.csv',
                                  './Donnees_brutes/data_chlorophylle_transparence',
                                  './Donnees_brutes/data_conditions_prelevement',
                                  './Donnees_brutes/data_physico_chimie',
                                  './Donnees_brutes/data_sonde_multiparamètres',
                                  './Donnees_brutes/data_phytoplancton',
                                  './Donnees_brutes/data_zooplancton'),
                         Fichier_correspondance=c(rep(NA,5),
                                                  './Donnees_brutes/corresp_taxon_phyto.csv',
                                                  './Donnees_brutes/corresp_taxon_zoo.csv'))
  for (k in 1:nrow(input_param)){
    if(input_param[k,]$Parametre=="Caracteristiques"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[k,]$rawCSV,fileEncoding = "UTF-8")
      write.csv(Caracteristiques_lacs_csv,paste0('./Donnees_compilees/Lacs_data_Caracteristiques.csv'),row.names = F,fileEncoding = "UTF-8")
   }else if(input_param[k,]$Parametre=="Chlorophylle"){
     message(paste0('Compilation de ',input_param[k,]$Parametre))
     Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Chlorophylle(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv)
    }else if(input_param[k,]$Parametre=="Transparence"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Transparence(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv)
    }else if(input_param[k,]$Parametre=="Physicochimie"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Physicochimie(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv)
    }else if(input_param[k,]$Parametre=="Multiparam"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Multiparam(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv)
    }else if(input_param[k,]$Parametre=="Phytoplancton"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Phytoplancton(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv,correspTax=input_param[k,]$Fichier_correspondance)
    }else if(input_param[k,]$Parametre=="Zooplancton"){
      message(paste0('Compilation de ',input_param[k,]$Parametre))
      Caracteristiques_lacs_csv=read.csv(input_param[input_param$Parametre=="Caracteristiques",]$rawCSV,fileEncoding = "UTF-8")
      compile_Zooplancton(folderwithrawcsv=input_param[k,]$rawCSV,correspLac=Caracteristiques_lacs_csv,correspTax=input_param[k,]$Fichier_correspondance)
    }else{
      next
    }
  }
}


compile_Chlorophylle=function(folderwithrawcsv,correspLac){
  filelist=list.files(path = folderwithrawcsv,pattern ="chlorophylle",full.names = T)
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    colnames(temp)=headtemp
    temp=temp[-1,]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    data_0=rbind(data_0,temp)
  }
  data_0=data_0[grep("chlorophylle a",data_0$nom.de.la.variable),]
  data_0$nom.de.la.variable="Chlorophylle a"
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=format(data_0$date.prélèvement,'%Y')
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0=data_0[,c("Massif","nom.du.site","Année","nom.de.la.variable","valeur","unité")]
  colnames(data_0)[colnames(data_0)%in%c("nom.du.site","nom.de.la.variable")]=c('Lac','Variable')
  data_0=data_0[order(data_0$Lac,data_0$Année),]
  data_0=data_0 %>%
    distinct()
  write.csv(data_0,paste0('./Donnees_compilees/Lacs_data_Chlorophylle.csv'),row.names = F,fileEncoding = "UTF-8")
}

compile_Transparence=function(folderwithrawcsv,correspLac){
  profondeurs=correspLac[,c('Lac','Profondeur.max..m.')]
  colnames(profondeurs)[2]="Profondeur"
  filelist=list.files(path = folderwithrawcsv,full.names = T)
  filelist=filelist[grep(pattern = '.csv',filelist)]
  filelist=filelist[grep(pattern = 'Informations_supplementaires',filelist,invert = T)]
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    colnames(temp)=headtemp
    temp=temp[-1,]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    data_0=rbind(data_0,temp)
  }
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=format(data_0$date.prélèvement,'%Y')
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0=data_0[,c("Massif","nom.du.site","Année","transparence.par.secchi.20.cm..m.")]
  data_0=data_0[is.na(data_0$transparence.par.secchi.20.cm..m.)==FALSE,]
  colnames(data_0)[colnames(data_0)%in%c("nom.du.site","transparence.par.secchi.20.cm..m.")]=c('Lac','Transparence')
  data_0=data_0[order(data_0$Lac,data_0$Année),]
  data_0=merge(data_0,profondeurs,by='Lac')
  data_0=data_0 %>%
    distinct()
  write.csv(data_0,paste0('./Donnees_compilees/Lacs_data_Transparence.csv'),row.names = F,fileEncoding = "UTF-8")
}


compile_Physicochimie=function(folderwithrawcsv,correspLac){
  filelist=list.files(path = folderwithrawcsv,pattern =".csv",full.names = T)
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    colnames(temp)=headtemp
    temp=temp[-1,]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    if(i==1){
      data_0=temp
    }else{
      data_0=rbind(data_0,temp[,colnames(temp)%in%colnames(data_0)])
    }
  }
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=format(data_0$date.prélèvement,'%Y')
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0$Zone=ifelse(data_0$profondeur.minimum..m.<=1,"Zone euphotique","Fond")
  
  data_1=data_0[data_0$paramètre%in%c("Calcium","Chlorures","Sodium","Magnesium","Potassium","Sulfates","Titre alcalimetrique complet","Nitrates", "Conductivité", "Ammonium", "Carbone organique total", "Phosphore Total", "Phosphore total filtré", "Azote total", "Azote total filtré"),]
  data_1[grep("Phosphore",data_1$paramètre),]$paramètre="Phosphore total filtré"
  data_1[grep("Azote total",data_1$paramètre),]$paramètre="Azote total filtré"
  data_1=data_1[,c("Massif","nom.du.site","Année","Zone","paramètre","valeur.du.résultat","unité")]
  colnames(data_1)[colnames(data_1)%in%c("nom.du.site","paramètre","valeur.du.résultat")]=c('Lac','Variable','Mesure')
  data_1=data_1[order(data_1$Lac,data_1$Année,data_1$Zone),]
  data_1$unité[data_1$unité=="milligramme par litre"]="mg/L"
  data_1$unité[data_1$unité=="mg(NO3)/l"]="mg/L"
  data_1$unité[data_1$unité=="mg(NH4)/l"]="mg/L"
  data_1$unité[data_1$unité=="milliéquivalent par litre"]="meq/L"
  data_1$unité[data_1$unité=="microsiemens  par centimètre"]="µS/cm"
  data_1=data_1 %>%
    distinct()
  write.csv(data_1,paste0('./Donnees_compilees/Lacs_data_Physicochimie.csv'))
  
  data_2=data_0[data_0$paramètre%in%c("Azote total", "Azote total filtré","Azote Ammonium","Azote Nitrates","Phosphore Total","Phosphore total filtré","Phosphore Orthophosphates","Carbone organique total"),]
  data_2[data_2$paramètre=="Phosphore total filtré",]$paramètre="Phosphore total"
  data_2[data_2$paramètre=="Phosphore Total",]$paramètre="Phosphore total"
  data_2[data_2$paramètre=="Phosphore Orthophosphates",]$paramètre="Phosphore ortho"
  data_2[grep("Azote total",data_2$paramètre),]$paramètre="Azote total"
  data_2[data_2$paramètre=="Azote Ammonium",]$paramètre="Azote ammoniacal"
  data_2[data_2$paramètre=="Azote Nitrates",]$paramètre="Azote nitrique"
  data_2=data_2[,c("Massif","nom.du.site","Année","Zone","paramètre","valeur.du.résultat","unité")]
  colnames(data_2)[colnames(data_2)%in%c("nom.du.site","paramètre","valeur.du.résultat")]=c('Lac','Variable','Mesure')
  data_2$unité="mg/L"
  data_2$part='A'
  
  data_3=data_0[data_0$paramètre%in%c("Calcium","Potassium","Magnésium","Sodium","Chlorures","Sulfates","Conductivité"),]
  data_3=data_3[,c("Massif","nom.du.site","Année","Zone","paramètre","valeur.du.résultat","unité")]
  colnames(data_3)[colnames(data_3)%in%c("nom.du.site","paramètre","valeur.du.résultat")]=c('Lac','Variable','Mesure')
  data_3[data_3$unité=="microsiemens  par centimètre",]$unité="µS/cm"
  data_3[data_3$unité=="milligramme par litre",]$unité="mg/L"
  data_3$part='B'
  
  data_2=rbind(data_2,data_3)
  data_2=data_2 %>%
    distinct()
  write.csv(data_2,paste0('./Donnees_compilees/Lacs_data_Physicochimie_qualiteEau.csv'),row.names = F,fileEncoding = "UTF-8")
}


compile_Multiparam=function(folderwithrawcsv,correspLac){
  filelist=list.files(path = folderwithrawcsv,full.names = T)
  filelist=filelist[grep(pattern = '.csv',filelist)]
  filelist=filelist[grep(pattern = 'Informations_supplementaires',filelist,invert = T)]
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    true_column_names = c("nom du projet", "nom du site", "nom de la plateforme", "outil de mesure", "commentaire sonde", "date de prélèvement", "heure", "profondeur réelle observée (m)", "chl a (mg/m3)", "cond25degres (ms/cm)", "oxygene mg (mg/l)", "oxygene saturation (%)", "ph brut (nounit)", "ph tc (nounit)", "Température (°c)")
    true_header_names = c("nom.du.projet", "nom.du.site", "nom.de.la.plateforme", "outil.de.mesure", "commentaire.sonde", "date.de.prélèvement", "heure", "profondeur.réelle.observée..m.", "chl.a..mg.m3.", "cond25degres..ms.cm.", "oxygene.mg..mg.l.", "oxygene.saturation....", "ph.brut..nounit.", "ph.tc..nounit.", "Température...c.")
    for (header_name in true_header_names) {
      if (length(grep(header_name, headtemp)) == 0){
        headtemp <- append(headtemp, list(x=header_name), 8)
        new_row = rep("", nrow(temp) - 1)
        new_row <- append(new_row, true_column_names[which(true_header_names == header_name)], 0)
        temp <- cbind(temp, new_row)
      }
    }
    # if (length(grep('chl.a..mg.m3.', headtemp)) == 0){
    #   headtemp <- append(headtemp, list(x='chl.a..mg.m3.'), 8)
    #   new_row = rep("", nrow(temp) - 1)
    #   new_row <- append(new_row, 'chl.a..mg.m3.', 0)
      

    #   temp$V14 <- new_row
    #   temp <- temp[, c("V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V14", "V9", "V10", "V11", "V12", "V13", "V14")]
    # }
    colnames(temp)=headtemp
    temp=temp[-1,]
    temp=temp[,colnames(temp)!="turbidite..ftu."]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    data_0=rbind(data_0,temp)
  }
  data_0=data_0[,colnames(data_0)%in%c("Massif","nom.du.site","date.prélèvement","profondeur.réelle.observée..m.","chl.a..mg.m3.","cond25degres..ms.cm.","oxygene.saturation....","Température...c.","ph.tc..nounit.")]
  data_0=data_0 %>%
    tidyr::pivot_longer(cols = !c("Massif","nom.du.site","date.prélèvement","profondeur.réelle.observée..m."),names_to = "Variable",values_to = "Mesure")
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=data.table::year(data_0$date.prélèvement)
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0$temp=gsub(pattern = '\\.',replacement = '_',data_0$Variable)
  data_0$Variable=do.call(rbind,strsplit(data_0$temp,'\\__'))[,1]
  data_0$unité=do.call(rbind,strsplit(data_0$temp,'\\__'))[,2]
  data_0$unité=gsub(pattern = '\\_',replacement = '.',data_0$unité)
  data_0$unité[data_0$unité=='nounit.']=""
  data_0$unité[data_0$unité=='.c.']="°C"
  data_0$unité[data_0$unité=='mg.m3.']="mg/m3"
  data_0$unité[data_0$unité=='ms.cm.']="ms/cm"
  data_0$unité[data_0$Variable=='oxygene_saturation']="%"
  data_0$Variable[data_0$Variable=='oxygene_saturation']="Saturation en oxygène"
  data_0$Variable[data_0$Variable=='chl_a']="Chlorophylle a"
  data_0$Variable[data_0$Variable=='cond25degres']="Conductivité"
  data_0$Variable[data_0$Variable=='ph_tc']="pH"
  data_0$Mesure=as.numeric(data_0$Mesure)
  data_0=data_0[is.na(data_0$Mesure)==FALSE,]
  data_0=data_0[,c("Massif","nom.du.site","Année","profondeur.réelle.observée..m.","Variable","Mesure","unité")]
  colnames(data_0)[colnames(data_0)%in%c("nom.du.site","profondeur.réelle.observée..m.")]=c('Lac','Profondeur')
  data_0=data_0[order(data_0$Lac,data_0$Année,data_0$Profondeur),]
  data_0=data_0%>%
    group_by(Massif,Lac,Année,Profondeur,Variable) %>%
    mutate(Mesure=mean(Mesure,na.rm=T))
  data_0=data_0 %>%
    distinct()
  write.csv(data_0,paste0('./Donnees_compilees/Lacs_data_Multiparam.csv'),row.names = F,fileEncoding = "UTF-8")
}


compile_Phytoplancton=function(folderwithrawcsv,correspLac,correspTax){
  corresp=read.csv(correspTax,fileEncoding = "UTF-8")
  corresp=corresp[(corresp$Classe=="")==FALSE,]
  filelist=list.files(path = folderwithrawcsv,full.names = T)
  filelist=filelist[grep(pattern = '.csv',filelist)]
  filelist=filelist[grep(pattern = 'Informations_supplementaires',filelist,invert = T)]
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    colnames(temp)=headtemp
    temp=temp[-1,]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    data_0=rbind(data_0,temp)
  }
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=format(data_0$date.prélèvement,'%Y')
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0=data_0[data_0$paramètre=="nombre de cellules par ml",]
  data_0=data_0[,c("Massif","nom.du.site","Année","nom.du.taxon.déterminé","valeur.du.résultat","paramètre","unité")]
  data_0=merge(data_0,corresp[,c("Taxon","Classe")],by.x="nom.du.taxon.déterminé",by.y='Taxon')
  data_0=data_0[,c("Massif","nom.du.site","Année","Classe","nom.du.taxon.déterminé","valeur.du.résultat","paramètre","unité")]
  colnames(data_0)[colnames(data_0)%in%c("nom.du.site","Classe","nom.du.taxon.déterminé","valeur.du.résultat")]=c('Lac','Groupe','Espèce',"Mesure")
  data_0=data_0[order(data_0$Lac,data_0$Année,data_0$Groupe,data_0$Espèce),]
  data_0=data_0 %>%
    distinct()
  write.csv(data_0,paste0('./Donnees_compilees/Lacs_data_Phytoplancton.csv'),row.names = F,fileEncoding = "UTF-8")
}

compile_Zooplancton=function(folderwithrawcsv,correspLac,correspTax){
  corresp=read.csv(correspTax,fileEncoding = "UTF-8")
  filelist=list.files(path = folderwithrawcsv,full.names = T)
  filelist=filelist[grep(pattern = '.csv',filelist)]
  filelist=filelist[grep(pattern = 'Informations_supplementaires',filelist,invert = T)]
  data_0=NULL
  for (i in 1:length(filelist)){
    headtemp=colnames(read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = T))
    temp=read.csv(filelist[i],fileEncoding = "Windows-1252",sep = ";",header = F)
    temp=temp[,apply(temp,2,function(x) sum(is.na(x)==FALSE))!=0]
    colnames(temp)=headtemp
    temp=temp[-1,]
    if(sum(colnames(temp)=="date.de.prélèvement")>0){
      colnames(temp)[colnames(temp)=="date.de.prélèvement"]="date.prélèvement"
    }
    temp$Massif=correspLac[correspLac$Lac==unique(temp$nom.du.site),]$Massif
    data_0=rbind(data_0,temp)
  }
  data_0$date.prélèvement=as.Date(data_0$date.prélèvement,format='%d/%m/%Y')
  data_0$Année=format(data_0$date.prélèvement,'%Y')
  data_0$JourCalendaire=data.table::yday(data_0$date.prélèvement)
  # data_0=subset(data_0,data_0$JourCalendaire>=227 & data_0$JourCalendaire<=288) #15/08 au 15/10
  data_0=subset(data_0,data_0$JourCalendaire>=91 & data_0$JourCalendaire<=335) # du 01/04 (jour 91) au 01/12 (jour 335)
  data_0=data_0[,c("Massif","nom.du.site","Année","nom.du.taxon.déterminé","valeur","variable")]
  data_0=merge(data_0,corresp,by.x="nom.du.taxon.déterminé",by.y='Taxon')
  data_0=data_0[,c("Massif","nom.du.site","Année","Classe","nom.du.taxon.déterminé","valeur","variable")]
  colnames(data_0)[colnames(data_0)%in%c("nom.du.site","Classe","nom.du.taxon.déterminé","valeur")]=c('Lac','Groupe','Espèce',"Mesure")
  data_0=data_0[order(data_0$Lac,data_0$Année,data_0$Groupe,data_0$Espèce),]
  data_0=data_0 %>%
    distinct()
  write.csv(data_0,paste0('./Donnees_compilees/Lacs_data_Zooplancton.csv'),row.names = F,fileEncoding = "UTF-8")
}