From 376021889c3358daa06f22c4757dabe070f2f5d0 Mon Sep 17 00:00:00 2001 From: Robinlovelace Date: Thu, 2 Apr 2026 12:03:24 +0100 Subject: [PATCH] Fix rendering issues in Chapters 9 and 12 --- 09-mapping.Rmd | 9 ++++++++- 12-spatial-cv.Rmd | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/09-mapping.Rmd b/09-mapping.Rmd index fe25ad526..ada53f928 100644 --- a/09-mapping.Rmd +++ b/09-mapping.Rmd @@ -1108,8 +1108,15 @@ g1 = ggplot() + geom_sf(data = nz, aes(fill = Median_income)) + scale_x_continuous(breaks = c(170, 175)) g1 library(ggspatial) +# Refresh nz_elev to avoid 'external pointer is not valid' error +if (!exists("nz_elev")) { + nz_elev = terra::rast(system.file("raster/nz_elev.tif", package = "spDataLarge")) +} ggplot() + - layer_spatial(nz_elev) + + tryCatch(layer_spatial(nz_elev), error = function(e) { + nz_elev <<- terra::rast(system.file("raster/nz_elev.tif", package = "spDataLarge")) + layer_spatial(nz_elev) + }) + geom_sf(data = nz, fill = NA) + annotation_scale() + scale_x_continuous(breaks = c(170, 175)) + diff --git a/12-spatial-cv.Rmd b/12-spatial-cv.Rmd index 1db43b9dd..9d8688346 100644 --- a/12-spatial-cv.Rmd +++ b/12-spatial-cv.Rmd @@ -642,7 +642,7 @@ Let's have a look at the final AUROC\index{AUROC}: the model's ability to discri round(mean(score_spcv_svm$classif.auc), 2) ``` -It appears that the GLM\index{GLM} (aggregated AUROC\index{AUROC} was `r score[resampling_id == "repeated_spcv_coords" & learner_id == "classif.log_reg", round(mean(classif.auc), 2)]`) is slightly better than the SVM\index{SVM} in this specific case. +It appears that the GLM\index{GLM} (aggregated AUROC\index{AUROC} was `r round(mean(score[score$resampling_id == "repeated_spcv_coords" & score$learner_id == "classif.log_reg", "classif.auc"]), 2)`) is slightly better than the SVM\index{SVM} in this specific case. To guarantee an absolute fair comparison, one should also make sure that the two models use the exact same partitions -- something we have not shown here but have silently used in the background (see `code/12_cv.R` in the book's GitHub repository for more information). To do so, **mlr3** offers the functions `benchmark_grid()` and `benchmark()` [see also https://mlr3book.mlr-org.com/chapters/chapter3/evaluation_and_benchmarking.html#sec-benchmarking, @bischl_applied_2024]. We will explore these functions in more detail in the Exercises.