From f21c53bd0a33beaa358d0572c367a448ed13d25e Mon Sep 17 00:00:00 2001
From: Juliette Engelaere-Lefebvre
 <juliette.engelaere@developpement-durable.gouv.fr>
Date: Mon, 11 Jul 2022 14:53:53 +0200
Subject: [PATCH] =?UTF-8?q?Correction=20d'un=20bug=20dans=20`poster=5Fdata?=
 =?UTF-8?q?()`,=20la=20fonction=20plantait=20si=20les=20modalit=C3=A9s=20d?=
 =?UTF-8?q?'un=20facteur=20contenaient=20des=20caract=C3=A8res=20sp=C3=A9c?=
 =?UTF-8?q?iaux.=20Conversion=20des=20levels=20en=20caract=C3=A8res=20ACSI?=
 =?UTF-8?q?I=20avant=20post=20sur=20zz=5Fr=5Fdf=5Fdef?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 DESCRIPTION   | 5 +++--
 NAMESPACE     | 2 ++
 NEWS.md       | 3 +++
 R/get_data.R  | 2 +-
 R/post_data.R | 3 ++-
 dev_history.R | 1 +
 6 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index ace4835..a89ab33 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
 Package: datalibaba
 Title: Interface De Connexion a Une Base Posgres Postgis
-Version: 0.0.0.9002
+Version: 0.0.0.9003
 Authors@R: 
     c(person(given = "Maël",
              family = "Theulière",
@@ -32,7 +32,8 @@ Imports:
     magrittr,
     tibble,
     units,
-    tidyr
+    tidyr,
+    gtools
 Encoding: UTF-8
 LazyData: true
 Roxygen: list(markdown = TRUE)
diff --git a/NAMESPACE b/NAMESPACE
index 432161d..2c5fe8a 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -52,6 +52,7 @@ importFrom(dplyr,filter)
 importFrom(dplyr,mutate)
 importFrom(dplyr,pull)
 importFrom(dplyr,relocate)
+importFrom(dplyr,rename_with)
 importFrom(dplyr,select)
 importFrom(dplyr,summarise)
 importFrom(dplyr,transmute)
@@ -60,6 +61,7 @@ importFrom(fs,path)
 importFrom(fs,path_expand)
 importFrom(fs,path_home_r)
 importFrom(glue,glue)
+importFrom(gtools,ASCIIfy)
 importFrom(magrittr,"%>%")
 importFrom(odbc,odbc)
 importFrom(purrr,map)
diff --git a/NEWS.md b/NEWS.md
index 7b75826..c01b4a0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,6 @@
+# datalibaba 0.0.0.9003
+- Correction d'un bug dans `poster_data()`, la fonction plantait si les modalités d'un facteur contenaient des caractères spéciaux.
+
 # datalibaba 0.0.0.9002
 - Correction d'un bug dans la fonction `importer_data()` : nommage du champ geo tel qu'il avait été chargé
 
diff --git a/R/get_data.R b/R/get_data.R
index 04b4be6..a9279ff 100644
--- a/R/get_data.R
+++ b/R/get_data.R
@@ -59,7 +59,7 @@ get_data_dbi <- function(con = NULL,
 #' @return la table de donnees, au format dataframe ou sf dataframe si une colonne de type 'USER-DEFINED' est presente dans la table sgbd
 #' @importFrom attempt stop_if stop_if_not
 #' @importFrom DBI dbExistsTable dbReadTable dbDisconnect
-#' @importFrom dplyr filter arrange select all_of relocate
+#' @importFrom dplyr filter arrange select all_of relocate rename_with
 #' @importFrom rlang .data
 #' @importFrom rpostgis dbTableInfo
 #' @importFrom sf st_read st_drop_geometry st_geometry
diff --git a/R/post_data.R b/R/post_data.R
index 82e9400..3758fc0 100644
--- a/R/post_data.R
+++ b/R/post_data.R
@@ -42,6 +42,7 @@ post_data <- function(con,
 #' @param overwrite TRUE si on veut ecraser le fichier deja present.
 #' @importFrom attempt stop_if stop_if_not
 #' @importFrom DBI dbWriteTable Id dbSendQuery
+#' @importFrom gtools ASCIIfy
 #' @importFrom glue glue
 #'
 #' @return NULL, la fonction lance le chargement du dataset present dans l'environnement R et son ecriture sur le serveur
@@ -199,7 +200,7 @@ poster_data <- function(data = NULL,
                  paste(as.character(attr2), collapse = ","), "},{",
                  paste(noms_r, collapse = ","), "}}")
 
-  defs2 <- data.frame(table_nm = table, df_def = defs)
+  defs2 <- data.frame(table_nm = table, df_def = gtools::ASCIIfy(defs))
   suppressWarnings(suppressMessages({
     rpostgis::pgInsert(con, c(schema, "zz_r_df_def"), defs2, upsert.using = "table_nm",
                        row.names = FALSE)
diff --git a/dev_history.R b/dev_history.R
index 19d5f1f..214801c 100644
--- a/dev_history.R
+++ b/dev_history.R
@@ -25,6 +25,7 @@ usethis::use_package("rlang")
 usethis::use_package("units")
 usethis::use_package("tibble")
 usethis::use_package("tidyr")
+usethis::use_package("gtools")
 attachment::att_amend_desc()
 devtools::document()
 pkgdown::build_site()
-- 
GitLab