From 772c04c7d8f92ee284d68e5d002e951dd8efba54 Mon Sep 17 00:00:00 2001
From: Christian Roever <christian.roever@med.uni-goettingen.de>
Date: Wed, 14 Sep 2022 09:20:22 +0200
Subject: [PATCH] fixed 'class()' calls

---
 R/bayesmeta.R |  4 ++--
 R/bmr.R       | 56 +++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/R/bayesmeta.R b/R/bayesmeta.R
index c2e4d4e..f5fac88 100644
--- a/R/bayesmeta.R
+++ b/R/bayesmeta.R
@@ -792,7 +792,7 @@ bayesmeta.default <- function(y, sigma, labels=names(y),
                                    c("tau","mu","theta")))
   expectation <- try(integrate(function(x)return(dposterior(x)*x), lower=0, upper=Inf,
                                rel.tol=rel.tol.integrate, abs.tol=abs.tol.integrate)$value, silent=TRUE)
-  if (class(expectation)=="try-error") {
+  if (inherits(expectation, "try-error")) {
     expectation <- NA
     variance <- NA
   }
@@ -800,7 +800,7 @@ bayesmeta.default <- function(y, sigma, labels=names(y),
     variance <- try(integrate(function(x)return(dposterior(x)*(x-expectation)^2), lower=0, upper=Inf,
                               rel.tol=rel.tol.integrate, abs.tol=abs.tol.integrate)$value,
                     silent=TRUE)
-    if (class(variance)=="try-error")
+    if (inherits(variance, "try-error"))
       variance <- NA
   }
   sumstats[c("mean","sd"),"tau"] <- c(expectation, sqrt(variance))
diff --git a/R/bmr.R b/R/bmr.R
index 4fab5fc..2695595 100644
--- a/R/bmr.R
+++ b/R/bmr.R
@@ -63,9 +63,15 @@ beta.convert <- function(beta, which.beta, d, betanames)
   if (missing(which.beta)) { # default "which.beta"
     betaIdx <- 1:d
   } else {  # try to make sense of "which.beta" argument; general sanity checks:
+    #if (!is.vector(which.beta)
+    #    || (!is.element(class(which.beta),
+    #                    c("numeric", "integer", "logical", "character"))
+    #        | (length(which.beta) > d))) {
+    #  warning("Cannot make sense of \"which.beta\" argument (1).")
+    #}
     if (!is.vector(which.beta)
-        || (!is.element(class(which.beta),
-                        c("numeric", "integer", "logical", "character"))
+        || (!inherits(which.beta,
+                      c("numeric", "integer", "logical", "character"))
             | (length(which.beta) > d))) {
       warning("Cannot make sense of \"which.beta\" argument (1).")
     }
@@ -430,13 +436,23 @@ bmr.default <- function(y, sigma, labels = names(y),
               missing(beta) || (is.matrix(beta) | is.data.frame(beta) | is.vector(beta)))
     if (!missing(beta)) {
       if (!missing(which.beta)) { # general sanity checks
+        #if (!is.vector(which.beta)
+        #    || (!is.element(class(which.beta),
+        #                    c("numeric", "integer", "logical", "character"))
+        #        | ((class(which.beta)=="logical")
+        #            && ((length(which.beta) != d) | (sum(which.beta)!=1)))
+        #        | ((is.element(class(which.beta),
+        #                       c("numeric", "integer", "character"))
+        #            & (length(which.beta) != 1))))) {
+        #  warning("Cannot make sense of \"which.beta\" argument (1).")
+        #}
         if (!is.vector(which.beta)
-            || (!is.element(class(which.beta),
-                            c("numeric", "integer", "logical", "character"))
-                | ((class(which.beta)=="logical")
+            || (!inherits(which.beta,
+                          c("numeric", "integer", "logical", "character"))
+                | (inherits(which.beta, "logical")
                     && ((length(which.beta) != d) | (sum(which.beta)!=1)))
-                | ((is.element(class(which.beta),
-                               c("numeric", "integer", "character"))
+                | ((inherits(which.beta,
+                             c("numeric", "integer", "character"))
                     & (length(which.beta) != 1))))) {
           warning("Cannot make sense of \"which.beta\" argument (1).")
         }
@@ -517,13 +533,23 @@ bmr.default <- function(y, sigma, labels = names(y),
               missing(beta.p) || (is.matrix(beta.p) | is.data.frame(beta.p) | is.vector(beta.p)))
     if (!missing(beta.p)) {
       if (!missing(which.beta)) { # general sanity checks
+        #if (!is.vector(which.beta)
+        #    || (!is.element(class(which.beta),
+        #                    c("numeric", "integer", "logical", "character"))
+        #        | ((class(which.beta)=="logical")
+        #            & ((length(which.beta) != d) | (sum(which.beta) != 1)))
+        #        | ((is.element(class(which.beta),
+        #                       c("numeric", "integer", "character"))
+        #            & (length(which.beta) != 1))))) {
+        #  warning("Cannot make sense of \"which.beta\" argument (1).")
+        #}
         if (!is.vector(which.beta)
-            || (!is.element(class(which.beta),
-                            c("numeric", "integer", "logical", "character"))
-                | ((class(which.beta)=="logical")
-                    & ((length(which.beta) != d) | (sum(which.beta) != 1)))
-                | ((is.element(class(which.beta),
-                               c("numeric", "integer", "character"))
+            || (!inherits(which.beta,
+                          c("numeric", "integer", "logical", "character"))
+                | (inherits(which.beta,"logical")
+                   & ((length(which.beta) != d) | (sum(which.beta) != 1)))
+                | ((inherits(which.beta,
+                             c("numeric", "integer", "character"))
                     & (length(which.beta) != 1))))) {
           warning("Cannot make sense of \"which.beta\" argument (1).")
         }
@@ -1248,7 +1274,7 @@ bmr.default <- function(y, sigma, labels = names(y),
                                lower=0, upper=Inf,
                                rel.tol=rel.tol.integrate,
                                abs.tol=abs.tol.integrate)$value, silent=TRUE)
-  if (class(expectation)=="try-error") {
+  if (inherits(expectation,"try-error")) {
     expectation <- NA
     variance <- NA
   } else {
@@ -1256,7 +1282,7 @@ bmr.default <- function(y, sigma, labels = names(y),
                               lower=0, upper=Inf,
                               rel.tol=rel.tol.integrate,
                               abs.tol=abs.tol.integrate)$value, silent=TRUE)
-    if (class(variance)=="try-error")
+    if (inherits(variance, "try-error"))
       variance <- NA
   }
   sumstats[c("mean","sd"), "tau"] <- c(expectation, sqrt(variance))
-- 
GitLab