diff --git a/R/get_data.R b/R/get_data.R index 27b0c4685a7830ab6f956cd42bbb9aa4a6356edb..9de25aa59aba1da2e405497ebbfe3d5a1d3d88ad 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 +#' @importFrom dplyr filter arrange select all_of relocate #' @importFrom rlang .data #' @importFrom rpostgis dbTableInfo #' @importFrom sf st_read st_drop_geometry st_geometry @@ -172,7 +172,7 @@ importer_data <- function(table = NULL, schema = NULL, db = "production", server # remettre le champ geometrie (au bon endroit) if(exists("data_sf") & nrow(def_table) > 0) { sf::st_geometry(data) <- sf::st_geometry(data_sf) - data <- dplyr::select(data, dplyr::all_of(defs$nms)) + data <- dplyr::relocate(data, dplyr::all_of(defs$nms)) } if(exists("data_sf") & nrow(def_table) == 0) { @@ -181,7 +181,7 @@ importer_data <- function(table = NULL, schema = NULL, db = "production", server # renommer avec les éventuels noms initiaux if(nrow(def_table) > 0) { - data <- dplyr::select(data, dplyr::all_of(defs$nms)) + data <- dplyr::relocate(data, dplyr::all_of(defs$nms)) names(data) <- defs$r_nms } diff --git a/R/post_data.R b/R/post_data.R index f15a0a7bfd5f8cf48bffc45c40570b863575c7b6..e5af9f792ccaa905fca334ab8a0a01eeb437ed32 100644 --- a/R/post_data.R +++ b/R/post_data.R @@ -223,6 +223,8 @@ poster_data <- function(data = NULL, ## Ecriture de la table : un comportement different pour les donnees spatiales et les autres dataframes------ if( any(grepl("sf", class(d))) ) { + attempt::warn_if(attributes(d)$sf_column != names(d)[ncol(d)], + msg = "La colonne geo n'est pas en fin de dataset, c'est une mauvaise pratique.") sf::st_write(obj = d, dsn = con, delete_layer = overwrite, layer = c(schema = schema, table = table)) # Ajout contrainte forcage crs ouverture couche crs <- sf::st_crs(x = d, parameters = TRUE)$epsg diff --git a/README.Rmd b/README.Rmd index 98074e52f5d5bd2a4db343fbd511087a85e785ac..ab3963b1fe9b40e1bad389a1f7bef7b115bf9479 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,6 +20,7 @@ knitr::opts_chunk$set( <!-- badges: end --> {datalibaba} est un ensemble de fonctions visant à faciliter l'alimentation du serveur de données du DREAL <datalab/> Pays de la Loire. +Site web de présentation du package : [https://dreal-datalab.gitlab.io/datalibaba/index.html](https://dreal-datalab.gitlab.io/datalibaba/index.html) ## Installation diff --git a/README.md b/README.md index 2e707416b9842f9c20f34dcd183b64df74a9db66..a9813e5e3272f2ce7c5eb3eed53daaf0e2b0bcb2 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ {datalibaba} est un ensemble de fonctions visant à faciliter l’alimentation du serveur de données du DREAL <datalab/> Pays de la -Loire. +Loire. Site web de présentation du package : +<https://dreal-datalab.gitlab.io/datalibaba/index.html> ## Installation @@ -75,7 +76,8 @@ La fonction `poster_data()` se veut plus complète : spatial, déclaration du CRS et du nb de dimensions de la géométrie) - poste quelques métadonnées en commentaire de la table (auteur du - chargement et sa date). + chargement et sa date) + - ajoute les droits de lecture/écriture du schéma à la table postée. Le schéma spécifié en argument est créé s’il n’existe pas.