From 6d971a40ef146f2779f6bb8a973e5371f46cff5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Grelot?= <frederic.grelot@irstea.fr>
Date: Wed, 14 Dec 2022 10:26:22 +0100
Subject: [PATCH] =?UTF-8?q?Pr=C3=A9paration=20de=20la=20version=20de=20la?=
 =?UTF-8?q?=20library=20so.ii=201.0.23.0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 dev/tag-message          | 28 +++++++++-------------------
 so.ii/DESCRIPTION        |  2 +-
 so.ii/NAMESPACE          |  2 ++
 so.ii/R/kable.R          | 34 ++++++++++++++++++++++++++++++++++
 so.ii/R/kable_units.r    |  3 ++-
 so.ii/R/linesep.R        | 29 +++++++++++++++++++++++++++++
 so.ii/man/kable.Rd       | 33 +++++++++++++++++++++++++++++++++
 so.ii/man/kable_units.Rd |  2 +-
 so.ii/man/linesep.Rd     | 32 ++++++++++++++++++++++++++++++++
 so.ii/man/map_so_ii.Rd   |  3 ++-
 10 files changed, 145 insertions(+), 23 deletions(-)
 create mode 100644 so.ii/R/kable.R
 create mode 100644 so.ii/R/linesep.R
 create mode 100644 so.ii/man/kable.Rd
 create mode 100644 so.ii/man/linesep.Rd

diff --git a/dev/tag-message b/dev/tag-message
index 9464e39..3a6fee2 100644
--- a/dev/tag-message
+++ b/dev/tag-message
@@ -1,27 +1,17 @@
-so.ii Version: 1.0.22.0
+so.ii Version: 1.0.23.0
 
 0 errors ✔ | 0 warnings ✔ | 0 notes ✔
 
 **Note de version**
-    * ajout de l'option scope à map_so_ii
-    * adaptation de l'option inset
-    * adaptation de l'option bar
+    * ajout de la fonction kable
+    * ajout de la fonction linesep
 
 **Détails**
-    * l'option "scope" (character) de map_so_ii permet de définir le scope de la
-        carte :
-        * si l'option est à "so-ii" (défaut), le périmètre total est affiché.
-        C'est le même comportement que précédemment.
-        * si l'option est un vecteur différent de "so-ii", alors il est cherché
-        l'ensemble des communes de so-ii dont le code INSEE correspond aux
-        valeurs de scope. Seules les bonnes valeurs sont gardées. Si aucune
-        bonne valeur n'est trouvée, un avertissement est lancé et la valeur par
-        d'afut est prise
-    * l'option "inset" permet de choisir la valeur "so-ii" pour situer un scope
-    plus petit que le périmètre total à l'intérieur de so-ii.
-    * l'option "bar" n'est pas mofifiée dans son appel, mais dans son
-    implémentation pour permettre d'ajuster la taille de la barre au scope
-    choisi.
+    * 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.
 
-# git tag -a v1.0.22.0 -F dev/tag-message
+# git tag -a v1.0.23.0 -F dev/tag-message
 # git push --tags
+
diff --git a/so.ii/DESCRIPTION b/so.ii/DESCRIPTION
index a46a835..bd22263 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.22.0
+Version: 1.0.23.0
 Authors@R:
     c(
         person(given = "Frédéric",
diff --git a/so.ii/NAMESPACE b/so.ii/NAMESPACE
index 359f568..d7b419e 100644
--- a/so.ii/NAMESPACE
+++ b/so.ii/NAMESPACE
@@ -4,6 +4,8 @@ export(add_inset)
 export(current_version)
 export(estimate_catnat_freq)
 export(format_presence)
+export(kable)
 export(kable_units)
+export(linesep)
 export(map_so_ii)
 export(plot_legend)
diff --git a/so.ii/R/kable.R b/so.ii/R/kable.R
new file mode 100644
index 0000000..48d42d1
--- /dev/null
+++ b/so.ii/R/kable.R
@@ -0,0 +1,34 @@
+#' @title Replace kable from kniter with some useful preset options
+#' 
+#' @param data object, something to be transform in a table
+#' @param ...  some parameters that will be used in original kable
+#'
+#' @return Somthing to be used as a table in latex format
+#'
+#' @export
+#'
+#' @encoding UTF-8
+#'
+#' @author Frédéric Grelot
+#' 
+#' @examples
+#'
+#' temp = head(iris)[c(5, 1:4)]
+#' temp[["Species"]] = as.character(temp[["Species"]])
+#' kable(temp)
+#' temp = rbind(temp, c(Species = "mean", as.list(colMeans(temp[-1]))))
+#' kable(temp, -1)
+#' temp = rbind(temp, c("units", "mm", "mm", "mm", "mm"))
+#' kable(temp, -1)
+ 
+kable = function(data, ...) {
+    knitr::kable(
+        data,
+        format = "latex",
+        booktabs = TRUE,
+        digits = 2,
+        format.args = list(big.mark = " ", scientific = FALSE, digit = 2),
+        ...
+    ) |>
+    kableExtra::kable_styling(position = "center")
+}
\ No newline at end of file
diff --git a/so.ii/R/kable_units.r b/so.ii/R/kable_units.r
index e8a7b95..53605f0 100644
--- a/so.ii/R/kable_units.r
+++ b/so.ii/R/kable_units.r
@@ -11,7 +11,8 @@
 #' @export
 #'
 #' @encoding UTF-8
-#' @author This is an adaptation of the function inset of the terra package.
+#' 
+#' @author Frédéric Grelot
 #' 
 #' @examples
 #' 
diff --git a/so.ii/R/linesep.R b/so.ii/R/linesep.R
new file mode 100644
index 0000000..9ccab37
--- /dev/null
+++ b/so.ii/R/linesep.R
@@ -0,0 +1,29 @@
+#' @title Create a linesep for kable
+#' 
+#' @param x vector, either numerical or logical, position for separation
+#' @param n integer, length of result
+#'
+#' @return A character vector of linesep to be used un kable. 
+#'
+#' @export
+#'
+#' @encoding UTF-8
+#' @author This is an adaptation of the function inset of the terra package.
+#' 
+#' @examples
+#' 
+#' temp = iris[sample(seq_len(nrow(iris)), 10),]
+#' kable(temp, linesep = linesep(diff(as.integer(temp[["Species"]])) != 0))
+#' kable(temp, linesep = linesep(temp[["Species"]][-1] != temp[["Species"]][-nrow(temp)]))
+#' 
+#' temp = temp[order(temp[["Species"]]), ]
+#' kable(temp, linesep = linesep(cumsum(table(temp[["Species"]]))))
+ 
+linesep = function(x, n) {
+    x = if (is.logical(x)) which(x) else as.integer(x)
+    if (missing(n)) n = max(x)
+    result = rep("", n)
+    result[x[x > 0]] = "\\midrule"
+    result[n + x[x < 0]] = "\\midrule"
+    return(result)
+}
diff --git a/so.ii/man/kable.Rd b/so.ii/man/kable.Rd
new file mode 100644
index 0000000..330517d
--- /dev/null
+++ b/so.ii/man/kable.Rd
@@ -0,0 +1,33 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/kable.R
+\encoding{UTF-8}
+\name{kable}
+\alias{kable}
+\title{Replace kable from kniter with some useful preset options}
+\usage{
+kable(data, ...)
+}
+\arguments{
+\item{data}{object, something to be transform in a table}
+
+\item{...}{some parameters that will be used in original kable}
+}
+\value{
+Somthing to be used as a table in latex format
+}
+\description{
+Replace kable from kniter with some useful preset options
+}
+\examples{
+
+temp = head(iris)[c(5, 1:4)]
+temp[["Species"]] = as.character(temp[["Species"]])
+kable(temp)
+temp = rbind(temp, c(Species = "mean", as.list(colMeans(temp[-1]))))
+kable(temp, -1)
+temp = rbind(temp, c("units", "mm", "mm", "mm", "mm"))
+kable(temp, -1)
+}
+\author{
+Frédéric Grelot
+}
diff --git a/so.ii/man/kable_units.Rd b/so.ii/man/kable_units.Rd
index 601d178..8471709 100644
--- a/so.ii/man/kable_units.Rd
+++ b/so.ii/man/kable_units.Rd
@@ -35,5 +35,5 @@ temp = rbind(temp, c("units", "mm", "mm", "mm", "mm"))
 kable_units(temp, -1)
 }
 \author{
-This is an adaptation of the function inset of the terra package.
+Frédéric Grelot
 }
diff --git a/so.ii/man/linesep.Rd b/so.ii/man/linesep.Rd
new file mode 100644
index 0000000..0c47d19
--- /dev/null
+++ b/so.ii/man/linesep.Rd
@@ -0,0 +1,32 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/linesep.R
+\encoding{UTF-8}
+\name{linesep}
+\alias{linesep}
+\title{Create a linesep for kable}
+\usage{
+linesep(x, n)
+}
+\arguments{
+\item{x}{vector, either numerical or logical, position for separation}
+
+\item{n}{integer, length of result}
+}
+\value{
+A character vector of linesep to be used un kable.
+}
+\description{
+Create a linesep for kable
+}
+\examples{
+
+temp = iris[sample(seq_len(nrow(iris)), 10),]
+kable(temp, linesep = linesep(diff(as.integer(temp[["Species"]])) != 0))
+kable(temp, linesep = linesep(temp[["Species"]][-1] != temp[["Species"]][-nrow(temp)]))
+
+temp = temp[order(temp[["Species"]]), ]
+kable(temp, linesep = linesep(cumsum(table(temp[["Species"]]))))
+}
+\author{
+This is an adaptation of the function inset of the terra package.
+}
diff --git a/so.ii/man/map_so_ii.Rd b/so.ii/man/map_so_ii.Rd
index 16ccac9..b7e4a85 100644
--- a/so.ii/man/map_so_ii.Rd
+++ b/so.ii/man/map_so_ii.Rd
@@ -126,7 +126,8 @@ If inset is not NULL, an inset will be plotted, depending on the value of
 as.character(inset). Non-case sensitive partial matching is used, with "é"
 interpreted as "e".
 \itemize{
-\item{\strong{so-ii}: scope perimeter is located within so-ii.}
+\item{\strong{so-ii}: scope perimeter is located within so-ii. Only
+useful when scope is less than so-ii.}
 \item{\strong{department}: scope perimeter is located within Hérault
 departement, if inset may be interpreted as "department", "département",
 "hérault", "34".}
-- 
GitLab