From 105a670c70f27474786c83f2e56b14ca84bb53de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20G=C3=A4rber?= <florian.gaerber@uni-hamburg.de>
Date: Thu, 20 Jul 2023 13:38:36 +0200
Subject: [PATCH] fix: Using if() conditions comparing class() to string

Now using inherits()
---
 R/var.relations.R          | 2 +-
 R/var.relations.mfi.R      | 2 +-
 R/variable_selection_mir.R | 2 +-
 R/variable_selection_smd.R | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/R/var.relations.R b/R/var.relations.R
index 9edc76a..f67f644 100644
--- a/R/var.relations.R
+++ b/R/var.relations.R
@@ -91,7 +91,7 @@ var.relations = function(x = NULL, y = NULL, num.trees = 500, type = "regression
         stop("Too much classes defined, classification might be the wrong choice")
       }
     }
-    if (type == "regression" && class(y) == "factor") {
+    if (type == "regression" && inherits(y, "factor")) {
       stop("use factor variable for y only for classification! ")
     }
 
diff --git a/R/var.relations.mfi.R b/R/var.relations.mfi.R
index 563fb23..043c9c4 100644
--- a/R/var.relations.mfi.R
+++ b/R/var.relations.mfi.R
@@ -93,7 +93,7 @@ var.relations.mfi = function(x = NULL, y = NULL, num.trees = 500, type = "regres
         stop("Too much classes defined, classification might be the wrong choice")
       }
     }
-    if (type == "regression" && class(y) == "factor") {
+    if (type == "regression" && inherits(y, "factor")) {
       stop("use factor variable for y only for classification! ")
     }
 
diff --git a/R/variable_selection_mir.R b/R/variable_selection_mir.R
index 090826b..f8ea84e 100644
--- a/R/variable_selection_mir.R
+++ b/R/variable_selection_mir.R
@@ -110,7 +110,7 @@ var.select.mir = function(x = NULL, y = NULL, num.trees = 500, type = "regressio
         stop("Too much classes defined, classification might be the wrong choice")
       }
     }
-    if (type == "regression" && class(y) == "factor") {
+    if (type == "regression" && inherits(y, "factor")) {
       stop("use factor variable for y only for classification! ")
     }
 
diff --git a/R/variable_selection_smd.R b/R/variable_selection_smd.R
index 35d6508..ef239f0 100644
--- a/R/variable_selection_smd.R
+++ b/R/variable_selection_smd.R
@@ -112,7 +112,7 @@ var.select.smd = function(x = NULL, y = NULL, num.trees = 500, type = "regressio
       stop("Too much classes defined, classification might be the wrong choice")
     }
   }
-  if (type == "regression" && class(y) == "factor") {
+  if (type == "regression" && inherits(y, "factor")) {
     stop("use factor variable for y only for classification! ")
   }
   data = data.frame(y, x)
-- 
GitLab