Running 'testthat.R' [104s]
Running the tests in 'tests/testthat.R' failed.
Complete output:
  > library(testthat)
  > library(rbmi)
  Warning messages:
  1: In checkMatrixPackageVersion() :
    Package version inconsistency detected.
  TMB was built with Matrix version 1.4.0
  Current Matrix version is 1.3.2
  Please re-install 'TMB' from source using install.packages('TMB', type = 'source') or ask CRAN for a binary version of 'TMB' matching CRAN's 'Matrix' package
  2: In checkDepPackageVersion(dep_pkg = "TMB") :
    Package version inconsistency detected.
  glmmTMB was built with TMB version 1.7.22
  Current TMB version is 1.8.0
  Please re-install glmmTMB from source or restore original 'TMB' package (see '?reinstalling' for more information)
  > 
  > test_check("rbmi")
  [ FAIL 34 | WARN 0 | SKIP 11 | PASS 781 ]
  
  == Skipped tests ===============================================================
  * is_nightly() is not TRUE (11)
  
  == Failed tests ================================================================
  -- Error (test-delta.R:260:5): extract_imputed_dfs + delta ---------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), use_samp_ids = FALSE, first_sample_orig = FALSE, 
      ncores = ncores, n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
          method$n_samples), quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-delta.R:260:4
   2. \-rbmi:::draws.approxbayes(...)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (test-draws.R:65:5): approxbayes --------------------------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), use_samp_ids = FALSE, first_sample_orig = FALSE, 
      ncores = ncores, n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
          method$n_samples), quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE) at test-draws.R:65:4
   2. \-rbmi:::draws.approxbayes(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (test-draws.R:80:5): condmean - bootstrap -----------------------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 5), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 5, failure_limit = 1, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE) at test-draws.R:80:4
   2. \-rbmi:::draws.condmean(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-draws.R:108:5): condmean - jackknife ----------------------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "jackknife"), class = c("method", 
  "condmean")), ncores = 1, first_sample_orig = TRUE, use_samp_ids = TRUE, 
      quiet = TRUE, n_target_samples = 20L, failure_limit = 0, 
      sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE) at test-draws.R:108:4
   2. \-rbmi:::draws.condmean(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-draws.R:130:5): bayes -------------------------------------------
  Error in `fit_mcmc(designmat = model_df_scaled[, -1, drop = FALSE], outcome = model_df_scaled[, 
      1, drop = TRUE], group = data2[[vars$group]], visit = data2[[vars$visit]], 
      subjid = data2[[vars$subjid]], method = method, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-base::suppressWarnings(...) at test-draws.R:130:4
   2. | \-base::withCallingHandlers(...)
   3. +-rbmi::draws(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE) at test-draws.R:131:8
   4. \-rbmi:::draws.bayes(d$dat, d$dat_ice, d$vars, meth, quiet = TRUE)
   5.   \-rbmi:::fit_mcmc(...)
  -- Error (test-draws.R:179:5): nmar data is removed as expected ----------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "jackknife"), class = c("method", 
  "condmean")), ncores = 1, first_sample_orig = TRUE, use_samp_ids = TRUE, 
      quiet = TRUE, n_target_samples = 20L, failure_limit = 0, 
      sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(dat, dat_ice, vars, method, quiet = TRUE) at test-draws.R:179:4
   2. \-rbmi:::draws.condmean(dat, dat_ice, vars, method, quiet = TRUE)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-draws.R:194:5): NULL data_ice works uses MAR by default ---------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 5), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 5, failure_limit = 1, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-draws.R:194:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-draws.R:280:5): Failure is handled properly ---------------------
  Error in `get_draws_mle(longdata = ld, method = method, n_target_samples = method$n_samples, 
      failure_limit = (method$threshold * method$n_samples), use_samp_ids = FALSE, 
      ncores = 1, first_sample_orig = FALSE, quiet = TRUE, sample_stack = stack)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. \-rbmi:::get_draws_mle(...) at test-draws.R:280:4
  -- Error (test-draws.R:462:5): draws is calling get_mmrm_sample properly -------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 2), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 2, failure_limit = 1, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(dat, dat_ice, vars, method, quiet = TRUE) at test-draws.R:462:4
   2. \-rbmi:::draws.condmean(dat, dat_ice, vars, method, quiet = TRUE)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-draws.R:578:5): draws.bmlmi works as expected -------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
      method$n_samples), use_samp_ids = TRUE, first_sample_orig = FALSE, 
      ncores = ncores, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-draws.R:578:4
   2. \-rbmi:::draws.bmlmi(...)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (???): quiet supress progress messages --------------------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), use_samp_ids = FALSE, first_sample_orig = FALSE, 
      ncores = ncores, n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
          method$n_samples), quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(data = dat, data_ice = dat_ice, vars = vars, method = method_approxbayes(n_samples = 3))
   2. \-rbmi:::draws.approxbayes(...)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (test-fullusage.R:894:5): Three arms trial runs smoothly and gives expected results --
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 0), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 0, failure_limit = 0, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-fullusage.R:894:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-impute.R:178:5): `references` is handled as expected ------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 0), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 0, failure_limit = 0, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(dat, data_ice, vars, method, quiet = TRUE) at test-impute.R:178:4
   2. \-rbmi:::draws.condmean(dat, data_ice, vars, method, quiet = TRUE)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (???): Verbose supression works ---------------------------------------
  Error in `fit_mcmc(designmat = model_df_scaled[, -1, drop = FALSE], outcome = model_df_scaled[, 
      1, drop = TRUE], group = data2[[vars$group]], visit = data2[[vars$visit]], 
      subjid = data2[[vars$subjid]], method = method, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...)
   2. \-rbmi:::draws.bayes(...)
   3.   \-rbmi:::fit_mcmc(...)
  -- Error (test-misc.R:44:5): rbmi can handle 'grouped' dplyr data --------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 10), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 10, failure_limit = 1, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-misc.R:44:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-misc.R:129:5): `rbmi` can handle character data -----------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.01, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 2), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 2, failure_limit = 1, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-misc.R:129:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Failure (test-mmrm.R:276:5): MMRM model fit has expected output structure (same_cov = TRUE) --
  `fit` has length 1, not length 4.
  Backtrace:
      x
   1. \-rbmi expect_valid_fit_object(fit, "us", 3, TRUE) at test-mmrm.R:276:4
   2.   \-testthat::expect_length(fit, 4) at test-mmrm.R:38:4
  -- Error (test-mmrm.R:276:5): MMRM model fit has expected output structure (same_cov = TRUE) --
  <vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
  Error in `stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)`: `fit$beta` must be a vector, not NULL.
  Backtrace:
       x
    1. \-rbmi expect_valid_fit_object(fit, "us", 3, TRUE) at test-mmrm.R:276:4
    2.   \-testthat::expect_vector(fit$beta) at test-mmrm.R:42:4
    3.     +-base::tryCatch(...)
    4.     | \-base tryCatchList(expr, classes, parentenv, handlers)
    5.     |   \-base tryCatchOne(expr, names, parentenv, handlers[[1L]])
    6.     |     \-base doTryCatch(return(expr), name, parentenv, handler)
    7.     \-vctrs::vec_assert(act$val, ptype = ptype, size = size, arg = act$lab)
    8.       \-vctrs:::stop_scalar_type(x, arg)
    9.         \-vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
   10.           \-rlang::abort(message, class = c(class, "vctrs_error"), ...)
  -- Failure (test-mmrm.R:305:5): MMRM model fit has expected output structure (same_cov = FALSE) --
  `fit` has length 1, not length 4.
  Backtrace:
      x
   1. \-rbmi expect_valid_fit_object(fit, "us", 3, FALSE) at test-mmrm.R:305:4
   2.   \-testthat::expect_length(fit, 4) at test-mmrm.R:38:4
  -- Error (test-mmrm.R:305:5): MMRM model fit has expected output structure (same_cov = FALSE) --
  <vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
  Error in `stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)`: `fit$beta` must be a vector, not NULL.
  Backtrace:
       x
    1. \-rbmi expect_valid_fit_object(fit, "us", 3, FALSE) at test-mmrm.R:305:4
    2.   \-testthat::expect_vector(fit$beta) at test-mmrm.R:42:4
    3.     +-base::tryCatch(...)
    4.     | \-base tryCatchList(expr, classes, parentenv, handlers)
    5.     |   \-base tryCatchOne(expr, names, parentenv, handlers[[1L]])
    6.     |     \-base doTryCatch(return(expr), name, parentenv, handler)
    7.     \-vctrs::vec_assert(act$val, ptype = ptype, size = size, arg = act$lab)
    8.       \-vctrs:::stop_scalar_type(x, arg)
    9.         \-vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
   10.           \-rlang::abort(message, class = c(class, "vctrs_error"), ...)
  -- Failure (test-mmrm.R:313:5): MMRM model fit has expected output structure (REML = FALSE) --
  `fit` has length 1, not length 4.
  Backtrace:
      x
   1. \-rbmi expect_valid_fit_object(fit, "us", 3, TRUE) at test-mmrm.R:313:4
   2.   \-testthat::expect_length(fit, 4) at test-mmrm.R:38:4
  -- Error (test-mmrm.R:313:5): MMRM model fit has expected output structure (REML = FALSE) --
  <vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
  Error in `stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)`: `fit$beta` must be a vector, not NULL.
  Backtrace:
       x
    1. \-rbmi expect_valid_fit_object(fit, "us", 3, TRUE) at test-mmrm.R:313:4
    2.   \-testthat::expect_vector(fit$beta) at test-mmrm.R:42:4
    3.     +-base::tryCatch(...)
    4.     | \-base tryCatchList(expr, classes, parentenv, handlers)
    5.     |   \-base tryCatchOne(expr, names, parentenv, handlers[[1L]])
    6.     |     \-base doTryCatch(return(expr), name, parentenv, handler)
    7.     \-vctrs::vec_assert(act$val, ptype = ptype, size = size, arg = act$lab)
    8.       \-vctrs:::stop_scalar_type(x, arg)
    9.         \-vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
   10.           \-rlang::abort(message, class = c(class, "vctrs_error"), ...)
  -- Error (test-mmrm.R:324:5): MMRM returns expected estimates (same_cov = TRUE) --
  Error in `.Call("getParameterOrder", data, parameters, new.env(), NULL, 
      PACKAGE = DLL)`: Incorrect number of arguments (4), expecting 3 for 'getParameterOrder'
  Backtrace:
      x
   1. \-glmmTMB::glmmTMB(...) at test-mmrm.R:324:4
   2.   \-glmmTMB::fitTMB(TMBStruc)
   3.     +-base::with(...)
   4.     \-base::with.default(...)
   5.       \-base::eval(substitute(expr), data, enclos = parent.frame())
   6.         \-base::eval(substitute(expr), data, enclos = parent.frame())
   7.           \-TMB::MakeADFun(...)
  -- Error (test-mmrm.R:348:5): MMRM returns expected estimates (same_cov = FALSE) --
  Error in `.Call("getParameterOrder", data, parameters, new.env(), NULL, 
      PACKAGE = DLL)`: Incorrect number of arguments (4), expecting 3 for 'getParameterOrder'
  Backtrace:
      x
   1. \-glmmTMB::glmmTMB(...) at test-mmrm.R:348:4
   2.   \-glmmTMB::fitTMB(TMBStruc)
   3.     +-base::with(...)
   4.     \-base::with.default(...)
   5.       \-base::eval(substitute(expr), data, enclos = parent.frame())
   6.         \-base::eval(substitute(expr), data, enclos = parent.frame())
   7.           \-TMB::MakeADFun(...)
  -- Failure (test-mmrm.R:377:5): MMRM model with multiple optimizers has expected output --
  `fit` has length 1, not length 4.
  Backtrace:
      x
   1. \-rbmi expect_valid_fit_object(fit1, "us", 3, FALSE) at test-mmrm.R:377:4
   2.   \-testthat::expect_length(fit, 4) at test-mmrm.R:38:4
  -- Error (test-mmrm.R:377:5): MMRM model with multiple optimizers has expected output --
  <vctrs_error_scalar_type/vctrs_error/rlang_error/error/condition>
  Error in `stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)`: `fit$beta` must be a vector, not NULL.
  Backtrace:
       x
    1. \-rbmi expect_valid_fit_object(fit1, "us", 3, FALSE) at test-mmrm.R:377:4
    2.   \-testthat::expect_vector(fit$beta) at test-mmrm.R:42:4
    3.     +-base::tryCatch(...)
    4.     | \-base tryCatchList(expr, classes, parentenv, handlers)
    5.     |   \-base tryCatchOne(expr, names, parentenv, handlers[[1L]])
    6.     |     \-base doTryCatch(return(expr), name, parentenv, handler)
    7.     \-vctrs::vec_assert(act$val, ptype = ptype, size = size, arg = act$lab)
    8.       \-vctrs:::stop_scalar_type(x, arg)
    9.         \-vctrs:::stop_vctrs(msg, "vctrs_error_scalar_type", actual = x)
   10.           \-rlang::abort(message, class = c(class, "vctrs_error"), ...)
  -- Error (test-mmrm.R:436:5): MMRM returns expected estimates under different model specifications --
  Error in `.Call("getParameterOrder", data, parameters, new.env(), NULL, 
      PACKAGE = DLL)`: Incorrect number of arguments (4), expecting 3 for 'getParameterOrder'
  Backtrace:
      x
   1. \-rbmi runtests(TRUE, FALSE) at test-mmrm.R:436:4
   2.   \-rbmi test_mmrm_numeric(dat, formula_expr, same_cov, scale) at test-mmrm.R:412:8
   3.     \-glmmTMB::glmmTMB(...) at test-mmrm.R:135:4
   4.       \-glmmTMB::fitTMB(TMBStruc)
   5.         +-base::with(...)
   6.         \-base::with.default(...)
   7.           \-base::eval(substitute(expr), data, enclos = parent.frame())
   8.             \-base::eval(substitute(expr), data, enclos = parent.frame())
   9.               \-TMB::MakeADFun(...)
  -- Error (test-mmrm.R:478:5): initial values speed up BFGS ---------------------
  <assertError/simpleError/error/condition>
  Error: Elements 1, 2 of c("beta", "theta") %in% names(optimizer[[i]]) are not true
  Backtrace:
      x
   1. +-rbmi:::time_it(...) at test-mmrm.R:478:4
   2. \-rbmi:::fit_mmrm_multiopt(...) at test-mmrm.R:479:8
   3.   \-assertthat::assert_that(all(c("beta", "theta") %in% names(optimizer[[i]])))
  -- Error (test-print.R:61:5): print - approx bayes -----------------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), use_samp_ids = FALSE, first_sample_orig = FALSE, 
      ncores = ncores, n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
          method$n_samples), quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-print.R:61:4
   2. \-rbmi:::draws.approxbayes(...)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (test-print.R:100:5): print - bayesian --------------------------------
  Error in `fit_mcmc(designmat = model_df_scaled[, -1, drop = FALSE], outcome = model_df_scaled[, 
      1, drop = TRUE], group = data2[[vars$group]], visit = data2[[vars$visit]], 
      subjid = data2[[vars$subjid]], method = method, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-base::suppressWarnings(...) at test-print.R:100:4
   2. | \-base::withCallingHandlers(...)
   3. +-rbmi::draws(...) at test-print.R:101:8
   4. \-rbmi:::draws.bayes(...)
   5.   \-rbmi:::fit_mcmc(...)
  -- Error (test-print.R:142:5): print - condmean bootstrap ----------------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "ar1", 
      threshold = 0.2, same_cov = TRUE, REML = TRUE, type = "bootstrap", 
      n_samples = 0), class = c("method", "condmean")), ncores = 1, 
      first_sample_orig = TRUE, use_samp_ids = TRUE, quiet = TRUE, 
      n_target_samples = 0, failure_limit = 0, sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-print.R:142:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-print.R:187:5): print - condmean jackknife ----------------------
  Error in `(function (longdata, method, sample_stack, n_target_samples, 
      first_sample_orig, use_samp_ids, failure_limit = 0, ncores = 1, 
      quiet = FALSE) 
  {
      max_sample_attempts <- n_target_samples + failure_limit
      assert_that(length(sample_stack$stack) >= max_sample_attempts, 
          msg = sprintf("Only %s samples in the sample_stack, %s are required", 
              length(sample_stack$stack), max_sample_attempts))
      time_taken <- system.time({
          initial_sample <- get_mmrm_sample(ids = longdata$ids, 
              longdata = longdata, method = method, optimizer = c("L-BFGS-B", 
                  "BFGS"))
      })
      if (initial_sample$failed) {
          stop("Fitting MMRM to original dataset failed")
      }
      if (!quiet) {
          cat(sprintf("\nEstimated running time (assuming single core) is %s seconds\n\n", 
              round(time_taken[[3]] * n_target_samples, 2)))
      }
      optimizer <- list(`L-BFGS-B` = NULL, BFGS = initial_sample[c("beta", 
          "theta")])
      cl <- get_cluster(ncores)
      mmrm_sample <- encap_get_mmrm_sample(cl, longdata, method, 
          optimizer)
      samples <- list()
      n_failed_samples <- 0
      logger <- progressLogger$new(n_target_samples, quiet = quiet)
      while (length(samples) < n_target_samples) {
          ids <- sample_stack$pop(min(ncores, n_target_samples - 
              length(samples)))
          new_samples <- mmrm_sample(ids)
          isfailure <- vapply(new_samples, function(x) x$failed, 
              logical(1))
          new_samples_keep <- new_samples[!isfailure]
          n_failed_samples <- n_failed_samples + sum(isfailure)
          if (n_failed_samples > failure_limit) {
              if (!is.null(cl)) 
                  parallel::stopCluster(cl)
              if (!is.null(method$type)) {
                  if (method$type == "jackknife") {
                    ids_fail <- ids[isfailure][[1]]
                    ids_jack <- longdata$ids[!longdata$ids %in% 
                      ids_fail][[1]]
                    msg <- "MMRM failed to fit to the data after removing subject '%s'"
                    stop(sprintf(msg, ids_jack))
                  }
              }
              msg <- "More than %s failed fits. Try using a simpler covariance structure"
              stop(sprintf(msg, failure_limit))
          }
          logger$add(length(new_samples_keep))
          samples <- append(samples, new_samples_keep)
      }
      if (!is.null(cl)) 
          parallel::stopCluster(cl)
      assert_that(length(samples) == n_target_samples, msg = "Incorrect number of samples were produced")
      if (first_sample_orig) {
          samples <- append(list(initial_sample), samples)
      }
      if (!use_samp_ids) {
          for (i in seq_along(samples)) {
              samples[[i]]$ids <- longdata$ids
          }
      }
      ret <- as_draws(method = method, samples = sample_list(samples), 
          data = longdata, formula = longdata$formula, n_failures = n_failed_samples)
      return(ret)
  })(longdata = <environment>, method = structure(list(covariance = "us", 
      threshold = 0.5, same_cov = FALSE, REML = TRUE, type = "jackknife"), class = c("method", 
  "condmean")), ncores = 1, first_sample_orig = TRUE, use_samp_ids = TRUE, 
      quiet = TRUE, n_target_samples = 35L, failure_limit = 0, 
      sample_stack = <environment>)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-print.R:187:4
   2. \-rbmi:::draws.condmean(...)
   3.   +-base::do.call(get_draws_mle, sample_opts)
   4.   \-rbmi `<fn>`(...)
  -- Error (test-print.R:226:5): print - bmlmi -----------------------------------
  Error in `get_draws_mle(longdata = longdata, method = method, sample_stack = get_bootstrap_stack(longdata, 
      method), n_target_samples = method$n_samples, failure_limit = ceiling(method$threshold * 
      method$n_samples), use_samp_ids = TRUE, first_sample_orig = FALSE, 
      ncores = ncores, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-rbmi::draws(...) at test-print.R:226:4
   2. \-rbmi:::draws.bmlmi(...)
   3.   \-rbmi:::get_draws_mle(...)
  -- Error (test-reproducibility.R:119:5): bayes - seed argument works without set.seed --
  Error in `fit_mcmc(designmat = model_df_scaled[, -1, drop = FALSE], outcome = model_df_scaled[, 
      1, drop = TRUE], group = data2[[vars$group]], visit = data2[[vars$visit]], 
      subjid = data2[[vars$subjid]], method = method, quiet = quiet)`: Fitting MMRM to original dataset failed
  Backtrace:
      x
   1. +-base::suppressWarnings(...) at test-reproducibility.R:119:4
   2. | \-base::withCallingHandlers(...)
   3. +-rbmi::draws(dat, dat_ice, vars, meth, quiet = TRUE) at test-reproducibility.R:120:8
   4. \-rbmi:::draws.bayes(dat, dat_ice, vars, meth, quiet = TRUE)
   5.   \-rbmi:::fit_mcmc(...)
  
  [ FAIL 34 | WARN 0 | SKIP 11 | PASS 781 ]
  Error: Test failures
  Execution halted