From 26e64fe4be3b9299c3b59a1804bf345f027a71b6 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Tue, 12 May 2020 06:47:24 +0200 Subject: [PATCH] Fixed class-checking bugs --- R/computeRows.R | 2 +- R/isempty.R | 4 ++-- R/repmat.R | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/computeRows.R b/R/computeRows.R index 8c9a9c3..51b4c0f 100644 --- a/R/computeRows.R +++ b/R/computeRows.R @@ -6,7 +6,7 @@ #' @param ninds ninds #' @export computeRows <- function(rowsFromInd, inds, ninds) { - if (class(inds) != "matrix") inds <- as.matrix(inds) + if (!is(inds, "matrix")) inds <- as.matrix(inds) if (identical(dim(inds), c(nrow(inds), 1L))) { # Special treatment for vectors because R has col vectors by default, # whereas Matlab has row vectors by default. diff --git a/R/isempty.R b/R/isempty.R index fada645..fe1730d 100644 --- a/R/isempty.R +++ b/R/isempty.R @@ -2,9 +2,9 @@ #' @description Determine whether array is empty. An empty array, table, or timetable has at least one dimension with length 0, such as 0-by-0 or 0-by-5. #' @details Emulates the behavior of the `isempty` function on Matlab #' @param x array -#' +#' isempty <- function(x) { - if (class(x) %in% c("array", "matrix")) { + if (class(x)[1] %in% c("array", "matrix")) { dim_mat_x <- dim(x) } else { dim_mat_x <- dim(matrix(x)) diff --git a/R/repmat.R b/R/repmat.R index 5c5e92f..630053f 100644 --- a/R/repmat.R +++ b/R/repmat.R @@ -14,7 +14,7 @@ repmat <- function (mx, n) { # Validation if (length(n) > 3) warning("Extra dimensions of n ignored") if (length(n) == 1) n <- rep(n, 2) - if (class(mx) != "matrix") mx <- as.matrix(mx) + if (!is(mx, "matrix")) mx <- as.matrix(mx) # Replicating cols out <- mx_col <- matrix(rep(mx, n[2]), nrow(mx))