From 435c2846fde061648bbb4036f78348047fcb6407 Mon Sep 17 00:00:00 2001
From: Johannes Knoch <jknoch@gfz-potsdam.de>
Date: Wed, 5 Oct 2022 12:01:52 +0200
Subject: [PATCH 1/2] bugfix for #69

---
 R-package/hasa/R/inner_procedure.r | 2 +-
 R-package/hasa/R/outer_procedure.r | 2 +-
 R-package/hasa/R/plot_results.r    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/R-package/hasa/R/inner_procedure.r b/R-package/hasa/R/inner_procedure.r
index b107477..f0d6758 100644
--- a/R-package/hasa/R/inner_procedure.r
+++ b/R-package/hasa/R/inner_procedure.r
@@ -128,7 +128,7 @@ sample_nb <- function(in_raster,
     n <- num_iterations
     sample_size <- r
     max_samples_per_class <- sample_size * 5
-    if (class(init_seed) == "character" && init_seed == "sample") {
+    if (inherits(init_seed, "character") && init_seed == "sample") {
       seed2 <- sample(c(1:1000000), size = num_models, replace = F)
     } else {
       seed2 <- init_seed
diff --git a/R-package/hasa/R/outer_procedure.r b/R-package/hasa/R/outer_procedure.r
index 339a891..125bd73 100644
--- a/R-package/hasa/R/outer_procedure.r
+++ b/R-package/hasa/R/outer_procedure.r
@@ -119,7 +119,7 @@ multi_Class_Sampling <- function(in_raster,
     }
   }
   ###first steps: data preparation
-  if (class(reference) == "SpatialPointsDataFrame") {
+  if (inherits(reference, "SpatialPointsDataFrame")) {
     reference <- as.data.frame(raster::extract(in_raster, reference))
   }
 
diff --git a/R-package/hasa/R/plot_results.r b/R-package/hasa/R/plot_results.r
index 10ca634..b902177 100644
--- a/R-package/hasa/R/plot_results.r
+++ b/R-package/hasa/R/plot_results.r
@@ -34,7 +34,7 @@ plot_results <- function(in_path, color = NULL) {
     # user's attention is drawn.
     if (length(list.files(
         in_path,
-        pattern = "step_(.*).tif",
+        pattern = "^step_(.*).tif$",
         all.files = FALSE,
         include.dirs = TRUE,
         no.. = TRUE
-- 
GitLab


From 3e915f13563c1a202281feb8004aeed627caaabd Mon Sep 17 00:00:00 2001
From: Johannes Knoch <jknoch@gfz-potsdam.de>
Date: Mon, 17 Oct 2022 14:06:56 +0200
Subject: [PATCH 2/2] error message for parameter references if no data.frame
 is provided

---
 R-package/hasa/R/outer_procedure.r | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/R-package/hasa/R/outer_procedure.r b/R-package/hasa/R/outer_procedure.r
index dedb352..17081d4 100644
--- a/R-package/hasa/R/outer_procedure.r
+++ b/R-package/hasa/R/outer_procedure.r
@@ -108,10 +108,13 @@ multi_Class_Sampling <- function(in_raster,
       return(NULL)
     }
   }
-  # ###first steps: data preparation
-  # if (inherits(reference, "SpatialPointsDataFrame")) {
-  #   reference <- as.data.frame(raster::extract(in_raster, reference))
-  # }
+  
+  # check if ref is provided correctly
+  if (!(inherits(reference, "data.frame"))) {
+    message("Parameter 'reference' isn't a data.frame. Please either use load_reference_as_table() or
+            load_reference_as_shape() to provide it correctly.")
+    return(NULL)
+  }
 
   #provide thresholds, reference, class_names and in_raster for reruns
   if (step != 1) {
-- 
GitLab