From 8aac025dd869d6a61c1089ca201bf0064844b7c8 Mon Sep 17 00:00:00 2001 From: Jean-Matthieu Monnet <jean-matthieu.monnet@inrae.fr> Date: Fri, 10 Feb 2023 16:19:39 +0100 Subject: [PATCH] Temporary fix to NA bug in terra::merge --- R/area-based.3.mapping.and.inference.Rmd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/area-based.3.mapping.and.inference.Rmd b/R/area-based.3.mapping.and.inference.Rmd index 0e0a310..9c6a78a 100755 --- a/R/area-based.3.mapping.and.inference.Rmd +++ b/R/area-based.3.mapping.and.inference.Rmd @@ -432,11 +432,11 @@ public_cropped <- sf::st_crop(public, terra::ext(metrics_map)) Then the function `lidaRtRee::aba_predict` is used to produce the map. If the input is an object containing the stratified model and if the metrics map contains the strata layer, then the model directly maps the output by retaining the corresponding model in each stratum. -```{r mapForestStratified, include=TRUE, message=FALSE, warning=FALSE} +```{r mapForestStratified, include=TRUE, message=FALSE, warning=TRUE} # map with stratified model prediction_map_mixed <- lidaRtRee::aba_predict(model_aba_stratified_mixed, metrics_map, stratum = "stratum") # ISSUE in terra::merge 1.7.3 : NA values are not handled correctly ? -# WAITING for a fix so that stratified maps are correctly merged +# CORRECTED in 1.7.8 for a fix so that stratified maps are correctly merged # for checking purposes # extracted "private" stratum model from combined model model_private <- list(model = model_aba_stratified_mixed$model$private, stats = model_aba_stratified_mixed$stats["private", ]) @@ -447,9 +447,10 @@ model_public <- list(model = model_aba_stratified_mixed$model$public, stats = mo # produce corresponding map prediction_map_public <- lidaRtRee::aba_predict(model_public, metrics_map) # TEMPORARY fix to NA values in terra::merge (call by lidaRtRee::aba_predict) -if (packageVersion("terra")<"1.7.3" | packageVersion("terra")>="1.7.8") +if (packageVersion("terra")>="1.7.3" && packageVersion("terra")<"1.7.8") { - warning("Merging with terra::mosaic because terra::merge in 1.7.3 and 1.7.6 does not handle NA values") + packageVersion("terra") + warning("Manually merging with terra::mosaic because terra::merge in 1.7.3 and 1.7.6 does not handle NA values") prediction_map_mixed <- terra::mosaic(prediction_map_public, prediction_map_private, fun = max) } ``` -- GitLab