Running ‘testthat.R’ [4s/6s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(biclustermd)
  Loading required package: ggplot2
  Loading required package: tidyr
  
  Attaching package: 'tidyr'
  
  The following object is masked from 'package:testthat':
  
      matches
  
  > 
  > test_check("biclustermd")
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  biclustermd
   --- call from context --- 
  biclustermd(synthetic)
   --- call from argument --- 
  if (!(class(data) %in% c("matrix", "data.frame"))) {
      stop("`data` must be a matrix or a data.frame.")
  }
   --- R stacktrace ---
  where 1 at testthat/test-autoplot_biclustermd.R#4: biclustermd(synthetic)
  where 2: eval(code, test_env)
  where 3: eval(code, test_env)
  where 4: withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error)
  where 5: doTryCatch(return(expr), name, parentenv, handler)
  where 6: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 7: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 10: tryCatchList(expr, classes, parentenv, handlers)
  where 11: tryCatch(withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error), error = handle_fatal, 
      skip = function(e) {
      })
  where 12: test_code(desc, code, env = parent.frame())
  where 13 at testthat/test-autoplot_biclustermd.R#3: test_that("autoplot_biclustermd() correctly plots cluster lines", 
      {
          sbc <- biclustermd(synthetic)
          ap <- ggplot2::ggplot_build(autoplot(sbc))
          expect_equal(ap$data[[3]]$xintercept[-1], cumsum(colSums(sbc$P)) + 
              0.5)
          expect_equal(ap$data[[4]]$yintercept[-1], cumsum(colSums(sbc$Q)) + 
              0.5)
      })
  where 14: eval(code, test_env)
  where 15: eval(code, test_env)
  where 16: withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error)
  where 17: doTryCatch(return(expr), name, parentenv, handler)
  where 18: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 19: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 22: tryCatchList(expr, classes, parentenv, handlers)
  where 23: tryCatch(withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error), error = handle_fatal, 
      skip = function(e) {
      })
  where 24: test_code(NULL, exprs, env)
  where 25: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 26: force(code)
  where 27: doWithOneRestart(return(expr), restart)
  where 28: withOneRestart(expr, restarts[[1L]])
  where 29: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 30: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter, 
      {
          reporter$start_file(basename(path))
          lister$start_file(basename(path))
          source_file(path, new.env(parent = env), chdir = TRUE, 
              wrap = wrap)
          reporter$.end_context()
          reporter$end_file()
      })
  where 31: FUN(X[[i]], ...)
  where 32: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 33: force(code)
  where 34: doWithOneRestart(return(expr), restart)
  where 35: withOneRestart(expr, restarts[[1L]])
  where 36: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 37: with_reporter(reporter = current_reporter, results <- lapply(paths, 
      test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE, 
      load_helpers = FALSE, wrap = wrap))
  where 38: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 39: test_dir(path = test_path, reporter = reporter, env = env, filter = filter, 
      ..., stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, 
      wrap = wrap)
  where 40: test_package_dir(package = package, test_path = test_path, filter = filter, 
      reporter = reporter, ..., stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 41: test_check("biclustermd")
  
   --- value of length: 2 type: logical ---
  [1] FALSE  TRUE
   --- function from context --- 
  function (data, row_clusters = floor(sqrt(nrow(data))), col_clusters = floor(sqrt(ncol(data))), 
      miss_val = mean(data, na.rm = TRUE), miss_val_sd = 1, similarity = "Rand", 
      row_min_num = floor(nrow(data)/row_clusters), col_min_num = floor(ncol(data)/col_clusters), 
      row_num_to_move = 1, col_num_to_move = 1, row_shuffles = 1, 
      col_shuffles = 1, max.iter = 100, verbose = FALSE) 
  {
      if (!(class(data) %in% c("matrix", "data.frame"))) {
          stop("`data` must be a matrix or a data.frame.")
      }
      if (class(data) == "data.frame") {
          data <- as.matrix(data)
      }
      if (is.null(rownames(data))) {
          stop("`data` does not have row names.")
      }
      if (is.null(colnames(data))) {
          stop("`data` does not have column names.")
      }
      if (is.expression(col_clusters)) {
          condition_call <- substitute(col_clusters)
          if (is.na(eval(condition_call))) {
              stop("`col_clusters` must not be NA.")
          }
          if (length(eval(condition_call)) > 0) {
              stop("`col_clusters` must be a single integer or function which evaluates to such.")
          }
      }
      else if (length(col_clusters) > 1) {
          stop("`col_clusters` must be a single integer or function which evaluates to such.")
      }
      if (is.expression(row_clusters)) {
          condition_call <- substitute(row_clusters)
          if (is.na(eval(condition_call))) {
              stop("`row_clusters` must not be NA.")
          }
          if (length(eval(condition_call)) > 0) {
              stop("`row_clusters` must be a single integer or function which evaluates to such.")
          }
      }
      else if (length(row_clusters) > 1) {
          stop("`row_clusters` must be a single integer or function which evaluates to such.")
      }
      if (length(similarity) > 1) {
          warning(paste0("Only one similarity metric can be used as a stopping condition. Using the first supplied, ", 
              similarity[1]))
          similarity <- similarity[1]
      }
      if (is.expression(miss_val)) {
          condition_call <- substitute(miss_val)
          if (is.na(eval(condition_call))) {
              stop("`miss_val` is NA")
          }
      }
      data <- as.matrix(data)
      m_d <- nrow(data)
      n_d <- ncol(data)
      P0 <- partition_gen(n_d, col_clusters)
      Q0 <- partition_gen(m_d, row_clusters)
      P <- P0
      Q <- Q0
      result_list <- vector("list", 11)
      names(result_list) <- c("params", "data", "P0", "Q0", "InitialSSE", 
          "P", "Q", "SSE", "Similarities", "iteration", "A")
      result_list$params <- mget(names(formals()), sys.frame(sys.nframe()))[-1]
      result_list$P0 <- P0
      result_list$Q0 <- Q0
      InitialSSE <- cluster_iteration_sum_sse(data, P, Q)
      SSE <- matrix(nrow = max.iter, ncol = 2)
      colnames(SSE) <- c("SSE", "Iteration")
      Similarities <- matrix(nrow = max.iter, ncol = 7)
      colnames(Similarities) <- c("P_rand", "P_ha", "P_jaccard", 
          "Q_rand", "Q_ha", "Q_jaccard", "Iteration")
      n_p <- ncol(P)
      n_q <- ncol(Q)
      s <- 0
      A <- matrix(nrow = n_q, ncol = n_p)
      p1 <- numeric(n_d)
      q1 <- numeric(m_d)
      dat2 <- data
      for (i in 1:m_d) {
          for (j in 1:n_d) {
              if (!is.na(data[i, j])) {
                  dat2[i, j] <- 1
              }
          }
      }
      while (s < max.iter) {
          if (verbose) {
              if (s%%10 == 0) {
                  cat("Iteration ", s, "\r")
              }
          }
          P_old <- P
          Q_old <- Q
          for (k in 1:row_shuffles) {
              for (j in 1:n_q) {
                  q_ind <- which(Q[, j] == 1)
                  for (i in 1:n_p) {
                    p_ind <- which(P[, i] == 1)
                    x_ij_prime <- data[q_ind, p_ind]
                    A[j, i] <- sum(x_ij_prime, na.rm = TRUE)/(length(x_ij_prime) - 
                      sum(is.na(x_ij_prime)))
                    if (is.na(A[j, i])) {
                      if (is.numeric(miss_val)) {
                        A[j, i] <- rnorm(1, miss_val, miss_val_sd)
                      }
                      else {
                        condition_call <- substitute(miss_val)
                        A[j, i] <- eval(condition_call)
                      }
                    }
                  }
              }
              col_cluster_mean <- matrix(0, nrow = m_d, ncol = n_p)
              distq <- matrix(nrow = m_d, ncol = n_q)
              dq <- matrix(0, nrow = n_q, ncol = n_p)
              for (i in 1:m_d) {
                  col_cluster_cnt <- apply(dat2[i, ] * P, 2, sum, 
                    na.rm = T)
                  col_cluster_mean[i, ] <- apply(data[i, ] * P, 
                    2, sum, na.rm = T)/col_cluster_cnt
                  col_cluster_mean[i, which(col_cluster_mean[i, 
                    ] == 0 | is.na(col_cluster_mean[i, ]))] <- miss_val
                  for (j in 1:n_q) {
                    dq[j, ] <- A[j, ] - col_cluster_mean[i, ]
                    distq[i, j] <- sum((dq[j, ]^2) * col_cluster_cnt, 
                      na.rm = TRUE)
                  }
              }
              q1 <- unlist(lapply(1:m_d, function(x) which.min(distq[x, 
                  ])), use.names = FALSE)
              Q <- partition_gen_by_p(m_d, n_q, q1)
              Q <- fill_empties_Q(data, Q, row_min_num, row_num_to_move)
          }
          for (k in 1:col_shuffles) {
              for (j in 1:n_q) {
                  q_ind <- which(Q[, j] == 1)
                  for (i in 1:n_p) {
                    p_ind <- which(P[, i] == 1)
                    x_ij_prime <- data[q_ind, p_ind]
                    A[j, i] <- sum(x_ij_prime, na.rm = TRUE)/(length(x_ij_prime) - 
                      sum(is.na(x_ij_prime)))
                    if (is.na(A[j, i])) {
                      if (is.numeric(miss_val)) {
                        A[j, i] <- rnorm(1, miss_val, miss_val_sd)
                      }
                      else {
                        condition_call <- substitute(miss_val)
                        A[j, i] <- eval(condition_call)
                      }
                    }
                  }
              }
              row_cluster_mean <- matrix(0, nrow = n_d, ncol = n_q)
              distp <- matrix(nrow = n_d, ncol = n_p)
              dp <- matrix(0, nrow = n_p, ncol = n_q)
              for (i in 1:n_d) {
                  row_cluster_cnt <- apply(dat2[, i] * Q, 2, sum, 
                    na.rm = T)
                  row_cluster_mean[i, ] <- apply(data[, i] * Q, 
                    2, sum, na.rm = T)/row_cluster_cnt
                  row_cluster_mean[i, which(row_cluster_mean[i, 
                    ] == 0 | is.na(row_cluster_mean[i, ]))] <- miss_val
                  for (j in 1:n_p) {
                    dp[j, ] <- A[, j] - row_cluster_mean[i, ]
                    distp[i, j] <- sum((dp[j, ]^2) * row_cluster_cnt)
                  }
              }
              p1 <- unlist(lapply(1:n_d, function(x) which.min(distp[x, 
                  ])), use.names = FALSE)
              P <- partition_gen_by_p(n_d, n_p, p1)
              P <- fill_empties_P(data, P, col_min_num, col_num_to_move)
          }
          s <- s + 1
          SSE[s, 1] <- cluster_iteration_sum_sse(data, P, Q)
          SSE[s, 2] <- s - 1
          P_old_vec <- part_matrix_to_vector(P_old) + 1
          P_new_vec <- part_matrix_to_vector(P) + 1
          Q_old_vec <- part_matrix_to_vector(Q_old) + 1
          Q_new_vec <- part_matrix_to_vector(Q) + 1
          P_sim <- adjustedRand(P_old_vec, P_new_vec, randMethod = similarity)
          Q_sim <- adjustedRand(Q_old_vec, Q_new_vec, randMethod = similarity)
          Similarities[s, 1:3] <- adjustedRand(P_old_vec, P_new_vec, 
              randMethod = c("Rand", "HA", "Jaccard"))
          Similarities[s, 4:6] <- adjustedRand(Q_old_vec, Q_new_vec, 
              randMethod = c("Rand", "HA", "Jaccard"))
          Similarities[s, 7] <- s - 1
          if ((P_sim == 1) && (Q_sim == 1)) {
              result_list$data <- data
              result_list$P <- P
              result_list$Q <- Q
              result_list$InitialSSE <- InitialSSE
              result_list$SSE <- SSE
              result_list$Similarities <- data.frame(Similarities)
              result_list$iteration <- s
              result_list$A <- A
              result_list$SSE <- result_list$SSE[1:s, ]
              result_list$Similarities <- result_list$Similarities[1:s, 
                  ]
              class(result_list$SSE) <- c("biclustermd_sse", "matrix")
              class(result_list$Similarities) <- c("biclustermd_sim", 
                  "data.frame")
              class(result_list) <- c("biclustermd", "list")
              result_list
              break
          }
      }
      result_list$data <- data
      result_list$P <- P
      result_list$Q <- Q
      result_list$InitialSSE <- InitialSSE
      result_list$SSE <- SSE
      result_list$Similarities <- data.frame(Similarities)
      result_list$SSE <- result_list$SSE[1:s, ]
      result_list$Similarities <- result_list$Similarities[1:s, 
          ]
      result_list$iteration <- s
      result_list$A <- A
      class(result_list$SSE) <- c("biclustermd_sse", "matrix")
      class(result_list$Similarities) <- c("biclustermd_sim", "data.frame")
      class(result_list) <- c("biclustermd", "list")
      result_list
  }
  <bytecode: 0x5565e9c61fa0>
  <environment: namespace:biclustermd>
   --- function search by body ---
  Function biclustermd in namespace biclustermd has this body.
   ----------- END OF FAILURE REPORT -------------- 
  Fatal error: the condition has length > 1