Running 'testthat.R' [10s/9s]
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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 1. Failure: Error with NA parameters (@test_bbt_run.R#11)  ------------------
  `bbt_run(rank | id ~ rider, data = gpheats[17:21, ], weight = "weight")` threw an error with unexpected message.
  Expected match: "Parameters error after evaluating id=5"
  Actual message: "the condition has length > 1"
  Backtrace:
   1. testthat::expect_error(...)
   6. sport::bbt_run(rank | id ~ rider, data = gpheats[17:21, ], weight = "weight")
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, init_r = 1000)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, data = data, init_r = 1000)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#25: expect_true(all(sum(bbt_run(formula = rank | id ~ name, data = data, 
      init_r = 1000)$final_r) == 4000))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#24: test_that("init r passed", {
      expect_true(all(sum(bbt_run(formula = rank | id ~ name, data = data, 
          init_r = 1000)$final_r) == 4000))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 2. Error: init r passed (@test_bbt_run.R#25)  -------------------------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(formula = rank | id ~ name, data = data, init_r = 1000)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, init_rd = 100)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, data = data, init_rd = 100)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#31: expect_true(all(bbt_run(formula = rank | id ~ name, data = data, 
      init_rd = 100)$final_rd < 100))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#30: test_that("init rd passed", {
      expect_true(all(bbt_run(formula = rank | id ~ name, data = data, 
          init_rd = 100)$final_rd < 100))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 3. Error: init rd passed (@test_bbt_run.R#31)  ------------------------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(formula = rank | id ~ name, data = data, init_rd = 100)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, gamma = 1.001, 
      rd = setNames(rep(26/6, 4), c("A", "B", "C", "D")))
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, data = data, gamma = 1.001, 
      rd = setNames(rep(26/6, 4), c("A", "B", "C", "D")))
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#35: expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
      data = data, gamma = 1.001, rd = setNames(rep(26/6, 4), c("A", 
          "B", "C", "D")))$final_r) > abs(25 - bbt_run(formula = rank | 
      id ~ name, data = data, gamma = 1.001, rd = setNames(rep(25/6, 
      4), c("A", "B", "C", "D")))$final_r)))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#34: test_that("bigger rating change for higher deviation", {
      expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
          data = data, gamma = 1.001, rd = setNames(rep(26/6, 4), 
              c("A", "B", "C", "D")))$final_r) > abs(25 - bbt_run(formula = rank | 
          id ~ name, data = data, gamma = 1.001, rd = setNames(rep(25/6, 
          4), c("A", "B", "C", "D")))$final_r)))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 4. Error: bigger rating change for higher deviation (@test_bbt_run.R#35)  ---
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(...)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, rd = rep(3, 
      4), sigma = "sigma")
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, data = data, rd = rep(3, 
      4), sigma = "sigma")
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#42: expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
      data = data, rd = rep(3, 4), sigma = "sigma")$final_r) > 
      abs(25 - bbt_run(formula = rank | id ~ name, data = data, 
          rd = rep(3, 4))$final_r)))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#41: test_that("bigger rating change for higher sigma", {
      expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
          data = data, rd = rep(3, 4), sigma = "sigma")$final_r) > 
          abs(25 - bbt_run(formula = rank | id ~ name, data = data, 
              rd = rep(3, 4))$final_r)))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 5. Error: bigger rating change for higher sigma (@test_bbt_run.R#42)  -------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(...)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, weight = "weight")
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1 at testthat/test_bbt_run.R#49: bbt_run(formula = rank | id ~ name, data = data, weight = "weight")
  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_bbt_run.R#48: test_that("R and RD exacltly proportional to weight", {
      model1 <- bbt_run(formula = rank | id ~ name, data = data, 
          weight = "weight")
      model2 <- bbt_run(formula = rank | id ~ name, data = data)
      expect_true(all(round(abs(25 - model1$final_r)/(abs(25 - 
          model2$final_r)), 2) == 1.05))
      expect_true(all(round(abs(25/3 - model1$final_rd)/(abs(25/3 - 
          model2$final_rd)), 2) == 1.05))
  })
  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("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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 6. Error: R and RD exacltly proportional to weight (@test_bbt_run.R#49)  ----
  the condition has length > 1
  Backtrace:
   1. sport::bbt_run(formula = rank | id ~ name, data = data, weight = "weight")
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ name, data = data, kappa = 0.99)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ name, data = data, kappa = 0.99)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#63: expect_true(all(bbt_run(rank | id ~ name, data = data, kappa = 0.99)$final_rd == 
      25/3 * 0.99))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#62: test_that("kappa is working", {
      expect_true(all(bbt_run(rank | id ~ name, data = data, kappa = 0.99)$final_rd == 
          25/3 * 0.99))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 7. Error: kappa is working (@test_bbt_run.R#63)  ----------------------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(rank | id ~ name, data = data, kappa = 0.99)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, beta = 25/3, data = data)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, beta = 25/3, data = data)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#69: expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
      beta = 25/3, data = data)$final_r) < abs(25 - bbt_run(formula = rank | 
      id ~ name, beta = 25/4, data = data)$final_r)))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#68: test_that("smaller rating change for higher beta", {
      expect_true(all(abs(25 - bbt_run(formula = rank | id ~ name, 
          beta = 25/3, data = data)$final_r) < abs(25 - bbt_run(formula = rank | 
          id ~ name, beta = 25/4, data = data)$final_r)))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 8. Error: smaller rating change for higher beta (@test_bbt_run.R#69)  -------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(formula = rank | id ~ name, beta = 25/3, data = data)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, gamma = 1.1, data = data)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, gamma = 1.1, data = data)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(object), label, arg = "object")
  where 4 at testthat/test_bbt_run.R#76: expect_true(all(bbt_run(formula = rank | id ~ name, gamma = 1.1, 
      data = data)$final_rd < bbt_run(formula = rank | id ~ name, 
      gamma = 1, data = data)$final_rd))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#75: test_that("bigger rd change for higher gamma", {
      expect_true(all(bbt_run(formula = rank | id ~ name, gamma = 1.1, 
          data = data)$final_rd < bbt_run(formula = rank | id ~ 
          name, gamma = 1, data = data)$final_rd))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 9. Error: bigger rd change for higher gamma (@test_bbt_run.R#76)  -----------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_true(...)
   4. sport::bbt_run(formula = rank | id ~ name, gamma = 1.1, data = data)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(formula = rank | id ~ name, data = data, idlab = "date")
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(formula = rank | id ~ name, data = data, idlab = "date")
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(expected), expected.label, arg = "expected")
  where 4 at testthat/test_bbt_run.R#83: expect_equal(as.character(data$date), attr(bbt_run(formula = rank | 
      id ~ name, data = data, idlab = "date")$r, "identifier"))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#82: test_that("identifier passed succesfuly", {
      expect_equal(as.character(data$date), attr(bbt_run(formula = rank | 
          id ~ name, data = data, idlab = "date")$r, "identifier"))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 10. Error: identifier passed succesfuly (@test_bbt_run.R#83)  ---------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_equal(...)
   4. sport::bbt_run(formula = rank | id ~ name, data = data, idlab = "date")
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ name, data = data)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ name, data = data)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(expected), expected.label, arg = "expected")
  where 4 at testthat/test_bbt_run.R#90: expect_identical(c("final_r", "final_rd", "r", "pairs"), names(bbt_run(rank | 
      id ~ name, data = data)))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#89: test_that("valid bbt output names", {
      expect_identical(c("final_r", "final_rd", "r", "pairs"), 
          names(bbt_run(rank | id ~ name, data = data)))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 11. Error: valid bbt output names (@test_bbt_run.R#90)  ---------------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_identical(...)
   4. sport::bbt_run(rank | id ~ name, data = data)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ name, data = data, weight = "weight", sigma = "sigma", 
      init_r = 1000, init_rd = 200)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ name, data = data, weight = "weight", sigma = "sigma", 
      init_r = 1000, init_rd = 200)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(expected), expected.label, arg = "expected")
  where 4 at testthat/test_bbt_run.R#97: expect_equal(list(names = c("final_r", "final_rd", "r", "pairs"), 
      class = "rating", method = "bbt", formula = rank | id ~ name, 
      settings = list(sigma = "sigma", weight = "weight", beta = 25/6, 
          kappa = 0.5, gamma = 999, idlab = "id", init_r = 1000, 
          init_rd = 200)), attributes(bbt_run(rank | id ~ name, 
      data = data, weight = "weight", sigma = "sigma", init_r = 1000, 
      init_rd = 200)))
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#96: test_that("valid bbt attr names", {
      expect_equal(list(names = c("final_r", "final_rd", "r", "pairs"), 
          class = "rating", method = "bbt", formula = rank | id ~ 
              name, settings = list(sigma = "sigma", weight = "weight", 
              beta = 25/6, kappa = 0.5, gamma = 999, idlab = "id", 
              init_r = 1000, init_rd = 200)), attributes(bbt_run(rank | 
          id ~ name, data = data, weight = "weight", sigma = "sigma", 
          init_r = 1000, init_rd = 200)))
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 12. Error: valid bbt attr names (@test_bbt_run.R#97)  -----------------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_equal(...)
   4. sport::bbt_run(...)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ name, data = data, weight = "weight", sigma = "sigma", 
      init_r = 1000, init_rd = 200)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ name, data = data, weight = "weight", sigma = "sigma", 
      init_r = 1000, init_rd = 200)
  where 2: eval_bare(expr, quo_get_env(quo))
  where 3: quasi_label(enquo(expected), expected.label, arg = "expected")
  where 4 at testthat/test_bbt_run.R#108: expect_identical(list(names = c("id", "name", "r", "rd", "p_win"), 
      class = c("data.table", "data.frame"), row.names = 1:4, identifier = as.character(c(1, 
          1, 1, 1))), attributes(bbt_run(rank | id ~ name, data = data, 
      weight = "weight", sigma = "sigma", init_r = 1000, init_rd = 200)$r)[-4])
  where 5: eval(code, test_env)
  where 6: eval(code, test_env)
  where 7: 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 8: doTryCatch(return(expr), name, parentenv, handler)
  where 9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 10: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 11: doTryCatch(return(expr), name, parentenv, handler)
  where 12: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 13: tryCatchList(expr, classes, parentenv, handlers)
  where 14: 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 15: test_code(desc, code, env = parent.frame())
  where 16 at testthat/test_bbt_run.R#107: test_that("r object has date labels attribute", {
      expect_identical(list(names = c("id", "name", "r", "rd", 
          "p_win"), class = c("data.table", "data.frame"), row.names = 1:4, 
          identifier = as.character(c(1, 1, 1, 1))), attributes(bbt_run(rank | 
          id ~ name, data = data, weight = "weight", sigma = "sigma", 
          init_r = 1000, init_rd = 200)$r)[-4])
  })
  where 17: eval(code, test_env)
  where 18: eval(code, test_env)
  where 19: 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 20: doTryCatch(return(expr), name, parentenv, handler)
  where 21: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 22: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 23: doTryCatch(return(expr), name, parentenv, handler)
  where 24: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 25: tryCatchList(expr, classes, parentenv, handlers)
  where 26: 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 27: test_code(NULL, exprs, env)
  where 28: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 29: force(code)
  where 30: doWithOneRestart(return(expr), restart)
  where 31: withOneRestart(expr, restarts[[1L]])
  where 32: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 33: 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 34: FUN(X[[i]], ...)
  where 35: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 36: force(code)
  where 37: doWithOneRestart(return(expr), restart)
  where 38: withOneRestart(expr, restarts[[1L]])
  where 39: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 40: 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 41: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 42: 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 43: 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 44: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 13. Error: r object has date labels attribute (@test_bbt_run.R#108)  --------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_identical(...)
   4. sport::bbt_run(...)
  
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  sport
   --- call from context --- 
  bbt_run(rank | id ~ name, data = data)
   --- call from argument --- 
  if (class(r) != "matrix") r <- as.matrix(r)
   --- R stacktrace ---
  where 1: bbt_run(rank | id ~ name, data = data)
  where 2: predict(bbt_run(rank | id ~ name, data = data), data)
  where 3: eval_bare(expr, quo_get_env(quo))
  where 4: quasi_label(enquo(object), label, arg = "object")
  where 5 at testthat/test_predict.R#34: expect_identical(round(predict(bbt_run(rank | id ~ name, data = data), 
      data)$P, 7), c(0.6215515, 0.2704624, 0.3784485, 0.3784485, 
      0.1841595, 0.2704624, 0.7295376, 0.8158405, 0.6215515, 0.6215515, 
      0.7295376, 0.3784485))
  where 6: eval(code, test_env)
  where 7: eval(code, test_env)
  where 8: 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 9: doTryCatch(return(expr), name, parentenv, handler)
  where 10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 11: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 12: doTryCatch(return(expr), name, parentenv, handler)
  where 13: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 14: tryCatchList(expr, classes, parentenv, handlers)
  where 15: 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 16: test_code(desc, code, env = parent.frame())
  where 17 at testthat/test_predict.R#33: test_that("valid bbt predict computation", {
      expect_identical(round(predict(bbt_run(rank | id ~ name, 
          data = data), data)$P, 7), c(0.6215515, 0.2704624, 0.3784485, 
          0.3784485, 0.1841595, 0.2704624, 0.7295376, 0.8158405, 
          0.6215515, 0.6215515, 0.7295376, 0.3784485))
  })
  where 18: eval(code, test_env)
  where 19: eval(code, test_env)
  where 20: 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 21: doTryCatch(return(expr), name, parentenv, handler)
  where 22: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 23: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 24: doTryCatch(return(expr), name, parentenv, handler)
  where 25: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 26: tryCatchList(expr, classes, parentenv, handlers)
  where 27: 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 28: test_code(NULL, exprs, env)
  where 29: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 30: force(code)
  where 31: doWithOneRestart(return(expr), restart)
  where 32: withOneRestart(expr, restarts[[1L]])
  where 33: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 34: 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 35: FUN(X[[i]], ...)
  where 36: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 37: force(code)
  where 38: doWithOneRestart(return(expr), restart)
  where 39: withOneRestart(expr, restarts[[1L]])
  where 40: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 41: 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 42: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 43: 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 44: 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 45: 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: 0x3303fc0>
  <environment: namespace:sport>
   --- function search by body ---
  Function bbt_run in namespace sport has this body.
   ----------- END OF FAILURE REPORT -------------- 
  -- 14. Error: valid bbt predict computation (@test_predict.R#34)  --------------
  the condition has length > 1
  Backtrace:
   1. testthat::expect_identical(...)
   5. sport::bbt_run(rank | id ~ name, data = data)
  
  == testthat results  ===========================================================
  [ OK: 55 | SKIPPED: 0 | WARNINGS: 0 | FAILED: 14 ]
  1. Failure: Error with NA parameters (@test_bbt_run.R#11) 
  2. Error: init r passed (@test_bbt_run.R#25) 
  3. Error: init rd passed (@test_bbt_run.R#31) 
  4. Error: bigger rating change for higher deviation (@test_bbt_run.R#35) 
  5. Error: bigger rating change for higher sigma (@test_bbt_run.R#42) 
  6. Error: R and RD exacltly proportional to weight (@test_bbt_run.R#49) 
  7. Error: kappa is working (@test_bbt_run.R#63) 
  8. Error: smaller rating change for higher beta (@test_bbt_run.R#69) 
  9. Error: bigger rd change for higher gamma (@test_bbt_run.R#76) 
  1. ...
  
  Error: testthat unit tests failed
  Execution halted