From 61ba101ca2817229ac9a731968550368adb204e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Thu, 20 Apr 2023 14:06:59 +0200
Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20so.ii=20v1.0.24.0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 dev/tag-message     | 15 +++++++--------
 so.ii/.Rbuildignore |  2 ++
 so.ii/DESCRIPTION   |  3 ++-
 so.ii/R/map_so_ii.r | 20 +++++++++++++++++---
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/dev/tag-message b/dev/tag-message
index 3a6fee2..da25973 100644
--- a/dev/tag-message
+++ b/dev/tag-message
@@ -1,17 +1,16 @@
-so.ii Version: 1.0.23.0
+so.ii Version: 1.0.24.0
 
 0 errors ✔ | 0 warnings ✔ | 0 notes ✔
 
 **Note de version**
-    * ajout de la fonction kable
-    * ajout de la fonction linesep
+    * modification de map_so_ii
 
 **Détails**
-    * kable masque knitr::kable en ajoutant des options très souvent utilisées
-    dans l'équipe (rapport ou présentation).
-    * linesep permet de créer facilement des vecteurs pour ajouter des
-    séparation avec l'option (non documentée) linesep de kable.
+    * map_so_ii charge dorénavant sf si besoin, modifie le parmètre sf_use_s2 à
+    FALSE (de façon momentanée). Il gère aussi le format de dataset. Il cherche
+    à le transformer en objet de classe sfc, s'il n'y arrive pas il renvoie un
+    warning et n'affiche pas dataset.
 
-# git tag -a v1.0.23.0 -F dev/tag-message
+# git tag -a v1.0.24.0 -F dev/tag-message
 # git push --tags
 
diff --git a/so.ii/.Rbuildignore b/so.ii/.Rbuildignore
index e829056..2c5b50b 100644
--- a/so.ii/.Rbuildignore
+++ b/so.ii/.Rbuildignore
@@ -1,4 +1,6 @@
+^data-common$
 ^data-raw$
+^data-raw/data-common$$
 ^dev$
 ^doc$
 ^Meta$
diff --git a/so.ii/DESCRIPTION b/so.ii/DESCRIPTION
index bd22263..aee78c7 100644
--- a/so.ii/DESCRIPTION
+++ b/so.ii/DESCRIPTION
@@ -1,6 +1,6 @@
 Package: so.ii
 Title: Utilities very useful to share within so_ii team
-Version: 1.0.23.0
+Version: 1.0.24.0
 Authors@R:
     c(
         person(given = "Frédéric",
@@ -23,6 +23,7 @@ LazyData: true
 Imports:
     kableExtra,
     knitr,
+    methods,
     readODS,
     rio,
     scales,
diff --git a/so.ii/R/map_so_ii.r b/so.ii/R/map_so_ii.r
index 43bb685..656fc2f 100644
--- a/so.ii/R/map_so_ii.r
+++ b/so.ii/R/map_so_ii.r
@@ -151,6 +151,10 @@ map_so_ii = function(
     add = FALSE,
     ...
 ) {
+    requireNamespace("sf")
+    osf = suppressMessages(sf::sf_use_s2(FALSE))
+    on.exit(suppressMessages(sf::sf_use_s2(osf)))
+
     theme = match.arg(theme)
 
     if (!is.null(path)) {
@@ -185,7 +189,7 @@ map_so_ii = function(
                 ),
                 stop(sprintf("%s not recognized", tolower(tools::file_ext(path))))
             )
-            on.exit(grDevices::dev.off())
+            on.exit(grDevices::dev.off(), add = TRUE, after = TRUE)
         } else {
             on.exit(
                 switch(
@@ -219,7 +223,8 @@ map_so_ii = function(
                         height = height / 2.54
                     ),
                     stop(sprintf("%s not recognized", tolower(tools::file_ext(path))))
-                )
+                ),
+                add = TRUE, after = TRUE
             )
             on.exit(grDevices::dev.off(), add = TRUE, after = TRUE)
         }
@@ -265,7 +270,16 @@ map_so_ii = function(
     )
 
     ## Plot dataset if any
-    if (!missing(dataset)) plot(dataset[["geometry"]], add = TRUE, ...)
+    if (!missing(dataset)) {
+        if (methods::is(dataset, "sf")) {
+            dataset = dataset[["geometry"]]
+        }
+        if (! methods::is(dataset, "sfc")) {
+            warning("'dataset' is not a sf or sfc object. It is not plotted.")
+        } else {
+            plot(dataset, add = TRUE, ...)
+        }
+    }
 
     ## Make scope visible
     if (limit == TRUE) {
-- 
GitLab