From fbe0a9c354153a89d62900a0e38d3f1b2c9f9532 Mon Sep 17 00:00:00 2001
From: de Lavenne Alban <alban.de-lavenne@irstea.fr>
Date: Tue, 24 Jan 2023 18:56:29 +0100
Subject: [PATCH] docs: improve again the handling of possible errors with
 whitebox

---
 .Rbuildignore                                 |  2 ++
 .gitignore                                    |  1 +
 DESCRIPTION                                   |  2 +-
 vignettes/V03_inputs_preparation_whitebox.Rmd | 16 ++++++++--------
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/.Rbuildignore b/.Rbuildignore
index 7774aab..829fb75 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -2,6 +2,8 @@
 ^\.Rproj\.user$
 package.json
 package-lock.json
+settings.json
+vignettes/settings.json
 node_modules
 ^doc$
 ^Meta$
diff --git a/.gitignore b/.gitignore
index 4691b38..5d54920 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@ MD5
 node_modules
 package.json
 package-lock.json
+settings.json
diff --git a/DESCRIPTION b/DESCRIPTION
index e77f5ec..03fd4bb 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,7 +2,7 @@ Package: transfR
 Type: Package
 Title: Transfer of Hydrograph from Gauged to Ungauged Catchments
 Version: 1.0.7
-Date: 2023-01-23
+Date: 2023-01-24
 Authors@R: c(
   person("Alban", "de Lavenne", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9448-3490"), email = "alban.delavenne@inrae.fr"),
   person("Christophe", "Cudennec", role = c("ths"), comment = c(ORCID = "0000-0002-1707-8926"), email = "christophe.cudennec@agrocampus-ouest.fr"),
diff --git a/vignettes/V03_inputs_preparation_whitebox.Rmd b/vignettes/V03_inputs_preparation_whitebox.Rmd
index 60466cf..ff6bb2a 100644
--- a/vignettes/V03_inputs_preparation_whitebox.Rmd
+++ b/vignettes/V03_inputs_preparation_whitebox.Rmd
@@ -40,7 +40,7 @@ The `elevatr` package allows retrieving grids (rasters) of elevation data worldw
 
 It is necessary to assign a geographic projection for the catchment delineation and hydraulic length maps with the `whitebox` package. We chose to use the Lambert93 projection, the official projection for maps of metropolitan France, for which the [EPSG code is 2154](https://epsg.io/2154).
 
-```{r, download_dem, echo=TRUE, message=FALSE, warning=FALSE, eval=TRUE, results='hide'}
+```{r, download_dem, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
 library(elevatr)
 library(rgdal) # Still often needed by elevatr
 library(progress) # Still often needed by elevatr
@@ -107,7 +107,7 @@ if(!wbt_init()){
   }
 ```
 
-```{r, burn_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
+```{r, burn_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
 library(transfR)
 library(whitebox)
 
@@ -158,7 +158,7 @@ The `whitebox` package provides all the tools to perform a usual catchment delin
 * [Delimit the catchments](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#Watershed).
 
 
-```{r, extract_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
+```{r, extract_stream, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
 # Remove the depressions on the DEM
 whitebox::wbt_fill_depressions(dem = "dem_100m_burn.tif",
                                output = "dem_fill.tif",
@@ -200,7 +200,7 @@ if(inherits(try_chunk, "try-error")){
 
 Coordinates of the outlets are retrieved from [hydro.eaufrance.fr](https://www.hydro.eaufrance.fr/) and snapped to the pixel of the river network that is consistent with the previously defined flow directions.
 
-```{r, delineate_catchments, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
+```{r, delineate_catchments, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
 # Localize the outlets of the studied catchments (with manual adjustments to help snapping)
 outlets_coordinates <- data.frame(id = names(Blavet$hl),
                              X = c(254010.612,255940-100,255903,237201,273672,265550),
@@ -228,9 +228,9 @@ for(id in outlets_snapped$id){
                           wd = wbt_wd)
   # Vectorize catchments
   drainage <- read_stars(file.path(wbt_wd, paste0(id, "_catchment.tif")))
-  contours <- st_contour(drainage, breaks = 1) |> st_cast("POLYGON")
-  contours <- contours[which.max(st_area(contours)),]
-  catchments <- rbind(catchments, st_sf(data.frame(id, geom = st_geometry(contours))))
+  contours <- st_contour(drainage, breaks = 1) |> st_geometry() |> st_cast("POLYGON")
+  contours <- contours[which.max(st_area(contours))]
+  catchments <- rbind(catchments, st_sf(data.frame(id, geom = contours)))
 }
 ```
 
@@ -274,7 +274,7 @@ The `whitebox` package does not provide a function to compute hydraulic length d
 Flow path lengths are computed once for all the study area. For each catchment, this raster is then trimmed (i.e. removing NA values outside the bounding box of the catchment) and the values of flow path lengths are corrected such as the minimum flow path length is equal to half a pixel width/height. The hydraulic lengths are finally gathered in a list as expected by the `as_transfr()` function.
 
 
-```{r, hydraulic_length, echo=TRUE, message=FALSE, warning=FALSE, eval=running, results='hide'}
+```{r, hydraulic_length, echo=TRUE, message=FALSE, warning=FALSE, eval=FALSE, results='hide'}
 # Compute hydraulic length
 whitebox::wbt_downslope_flowpath_length(d8_pntr = "d8.tif",
                                         output = "fpl.tif",
-- 
GitLab