Running ‘testthat.R’ [3s/5s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(sport)
  > 
  > test_check("sport")
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ rider, data = gpheats[17:21, ], weight = "weight")
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ rider, data = gpheats[17:21, ], weight = "weight")
  where 2: eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
  where 3: withCallingHandlers({
      code
      NULL
  }, error = function(cnd) {
      if (can_entrace(cnd)) {
          cnd <- cnd_entrace(cnd)
      }
      return_from(env, cnd)
  })
  where 4: .capture(act$val <- eval_bare(quo_get_expr(.quo), quo_get_env(.quo)), 
      ...)
  where 5: quasi_capture(enquo(object), label, capture_error, entrace = TRUE)
  where 6 at testthat/test_bbt_run.R#11: expect_error(bbt_run(rank | id ~ rider, data = gpheats[17:21, 
      ], weight = "weight"), paste0("Parameters error after evaluating id=", 
      gpheats$id[17]))
  where 7: eval(code, test_env)
  where 8: eval(code, test_env)
  where 9: 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 10: doTryCatch(return(expr), name, parentenv, handler)
  where 11: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 12: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 13: doTryCatch(return(expr), name, parentenv, handler)
  where 14: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 15: tryCatchList(expr, classes, parentenv, handlers)
  where 16: 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 17: test_code(desc, code, env = parent.frame())
  where 18 at testthat/test_bbt_run.R#9: test_that("Error with NA parameters", {
      gpheats$weight[17] <- NaN
      expect_error(bbt_run(rank | id ~ rider, data = gpheats[17:21, 
          ], weight = "weight"), paste0("Parameters error after evaluating id=", 
          gpheats$id[17]))
  })
  where 19: eval(code, test_env)
  where 20: eval(code, test_env)
  where 21: 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 22: doTryCatch(return(expr), name, parentenv, handler)
  where 23: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 24: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 25: doTryCatch(return(expr), name, parentenv, handler)
  where 26: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 27: tryCatchList(expr, classes, parentenv, handlers)
  where 28: 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 29: test_code(NULL, exprs, env)
  where 30: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 31: force(code)
  where 32: doWithOneRestart(return(expr), restart)
  where 33: withOneRestart(expr, restarts[[1L]])
  where 34: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 35: 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 36: FUN(X[[i]], ...)
  where 37: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 38: force(code)
  where 39: doWithOneRestart(return(expr), restart)
  where 40: withOneRestart(expr, restarts[[1L]])
  where 41: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 42: 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 43: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 44: 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 45: 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 46: test_check("sport")
  
   --- value of length: 2 type: logical ---
  [1] FALSE  TRUE
   --- function from context --- 
  function (formula, data, r, rd, sigma, weight, beta = 25/6, kappa = 0.5, 
      gamma, idlab, init_r = 25, init_rd = 25/3, pb = FALSE) 
  {
      is_formula_missing(formula)
      is_data_provided(data)
      is_lhs_valid(formula)
      is_rhs_valid(formula, "bbt_run")
      lhs <- all.vars(update(formula, . ~ 0))
      rhs <- all.vars(update(formula, 0 ~ .))
      y <- lhs[1]
      x <- rhs[1]
      id <- ifelse(length(lhs) == 1, "id", lhs[2])
      if (length(lhs) == 1) 
          data$id <- 1
      if (missing(r)) {
          message(paste("r is missing and will set to default="), 
              init_r)
          names <- unique(data[[x]])
          r <- as.matrix(setNames(rep(init_r, length(names)), names))
      }
      if (missing(rd)) {
          message(paste("rd is missing and will set to default="), 
              init_rd)
          names <- unique(data[[x]])
          rd <- as.matrix(setNames(rep(init_rd, length(names)), 
              names))
      }
      if (missing(sigma)) {
          data$sigma <- 0
          sigma <- "sigma"
      }
      if (missing(weight)) {
          data$weight <- 1
          weight <- "weight"
      }
      if (missing(gamma)) 
          gamma <- 999
      if (missing(idlab)) 
          idlab <- id
      if (kappa == 0) 
          kappa = 1e-04
      if (class(r) != "matrix") 
          r <- as.matrix(r)
      if (class(rd) != "matrix") 
          rd <- as.matrix(rd)
      if (any(class(data) == "data.frame")) 
          data_list <- split(data[unique(c(y, id, x, sigma, weight, 
              idlab))], data[[id]])
      n <- length(data_list)
      if (pb) {
          j <- 0
          pb <- txtProgressBar(min = 0, max = n, width = 20, initial = 0, 
              style = 3)
      }
      models <- list()
      for (i in names(data_list)) {
          team_name <- data_list[[i]][[x]]
          model <- bbt(team_name, rank = data_list[[i]][[y]], r = r[team_name, 
              , drop = FALSE], rd = rd[team_name, , drop = FALSE], 
              sigma = data_list[[i]][[sigma]], weight = data_list[[i]][[weight]], 
              kappa = kappa, beta = beta, gamma = gamma, identifier = as.character(data_list[[i]][[idlab]]), 
              init_r = init_r, init_rd = init_rd)
          if (any(!is.finite(model$rd) | !is.finite(model$r) | 
              model$rd < 0)) 
              stop(paste0("Parameters error after evaluating ", 
                  id, "=", i), call. = F)
          r[team_name, ] <- model$r[team_name, ]
          rd[team_name, ] <- model$rd[team_name, ]
          models[[i]] <- model
          if (pb) {
              j <- j + 1
              setTxtProgressBar(pb, j)
          }
      }
      model_r <- suppressWarnings(data.table::rbindlist(lapply(models, 
          function(x) x[["r_df"]]), use.names = T, idcol = "id"))
      model_P <- suppressWarnings(data.table::rbindlist(lapply(models, 
          function(x) x[["pairs"]]), use.names = T, idcol = "id"))
      identifierp <- unlist(lapply(models, `[[`, "identifierp"), 
          FALSE, FALSE)
      identifier <- unlist(lapply(models, `[[`, "identifier"), 
          FALSE, FALSE)
      class(model_r[[id]]) <- class(model_P[[id]]) <- class(data[[id]])
      p <- model_P[, .(p_win = prod(P)), by = c("id", "name")][, 
          `:=`(p_win, p_win/sum(p_win)), by = "id"]
      model_r <- merge(model_r, p, all.x = T, by = c("id", "name"), 
          sort = F)
      out <- structure(list(final_r = setNames(as.vector(r), rownames(r)), 
          final_rd = setNames(as.vector(rd), rownames(rd)), r = structure(model_r, 
              identifier = identifier), pairs = structure(model_P, 
              identifier = identifierp)), class = "rating", method = "bbt", 
          formula = formula, settings = list(sigma = sigma, weight = weight, 
              beta = beta, kappa = kappa, gamma = gamma, idlab = idlab, 
              init_r = init_r, init_rd = init_rd))
      return(out)
  }
  <bytecode: 0x555ca719d868>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  Fatal error: the condition has length > 1