Skip to content

Commit

Permalink
removing unorthdox console output printing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshyam-k committed Feb 9, 2024
1 parent 3d5d6a4 commit b257050
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 38 deletions.
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ Imports:
future,
methods,
rlang,
Rcpp,
cli
Rcpp
RoxygenNote: 7.3.1
Suggests:
testthat (>= 3.0.0)
Expand All @@ -37,5 +36,4 @@ Depends:
R (>= 4.1.0)
LinkingTo:
Rcpp,
RcppEigen,
cli
RcppEigen
28 changes: 1 addition & 27 deletions R/saeczi.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ saeczi <- function(samp_dat,
message("See <https://future.futureverse.org/reference/plan.html> for reference on how to use `future::plan()`")
}

w <- options("width")$width
header <- paste0(rep("=", w), collapse = "")
cat(cli::make_ansi_style("steelblue")(header), "\n", sep = "")
cat(cli::style_bold(cli::col_black("\u2022 Fitting Models...")))
cat("\n")
# creating strings of original X, Y names
Y <- deparse(lin_formula[[2]])

Expand Down Expand Up @@ -96,9 +91,6 @@ saeczi <- function(samp_dat,

if (mse_est) {

cat(cli::style_bold(cli::col_black("\u2022 Beginning Bootstrap...")))
cat("\n")

zi_model_coefs <- mse_coefs(
original_out$lmer,
original_out$glmer
Expand Down Expand Up @@ -218,9 +210,6 @@ saeczi <- function(samp_dat,

p <- progressor(steps = length(x))

cat("creating bootstraps...")
cat("\n")

res <-
furrr::future_map(.x = boot_lst,
.f = \(.x) {
Expand Down Expand Up @@ -252,8 +241,6 @@ saeczi <- function(samp_dat,
# down to positive response values
u_lm[is.na(u_lm)] <- 0

cat("estimating mse...")
cat("\n")
preds_full <- generate_mse(.data = boot_pop_data,
truth = boot_truth,
domain_level = domain_level,
Expand All @@ -279,9 +266,7 @@ saeczi <- function(samp_dat,
})

} else {
task_text <- " - Fitting to Bootstrap samples"
task_done <- paste0(task_text, cli::make_ansi_style("green4")(" \u2713"))
reset <- paste0(rep(" ", nchar(task_text)), collapse = " ")

res <-
purrr::map(.x = boot_samp_ls,
.f = \(.x) {
Expand All @@ -292,11 +277,8 @@ saeczi <- function(samp_dat,
},
.progress = list(
type = "iterator",
format = " - Fitting to Bootstrap samples {cli::pb_percent}",
clear = TRUE
))

cat("\r", reset, "\r", " ", task_done, "\n", sep = "")

beta_lm_mat <- res |>
map_dfr(.f = ~ .x$params$beta_lm) |>
Expand All @@ -318,9 +300,6 @@ saeczi <- function(samp_dat,
# down to positive response values
u_lm[is.na(u_lm)] <- 0

task_text <- " - Estimating MSE"
task_done <- paste0(task_text, cli::make_ansi_style("green4")(" \u2713"))
reset <- paste0(rep(" ", nchar(task_text)), collapse = " ")
preds_full <- generate_mse(.data = boot_pop_data,
truth = boot_truth,
domain_level = domain_level,
Expand All @@ -331,17 +310,13 @@ saeczi <- function(samp_dat,
lin_X = lin_X,
log_X = log_X)

cat("\r", reset, "\r", " ", task_done, "\n", sep = "")
log_lst <- res |>
map(.f = ~ .x$log)

boot_res <- list(preds_full, log_lst)

}

cat(cli::style_bold(cli::col_black("\u2022 Compiling Results...")))
cat("\n")
Sys.sleep(0.5)
final_df <- setNames(
boot_res[[1]],
c("domain", "mse")
Expand Down Expand Up @@ -376,7 +351,6 @@ saeczi <- function(samp_dat,
lin_mod = original_out$lmer,
log_mod = original_out$glmer
)
cat(cli::make_ansi_style("steelblue")(header), "\n", sep = "")

structure(out, class = "zi_mod")

Expand Down
8 changes: 1 addition & 7 deletions src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <cmath>
#include <Rcpp.h>
#include <RcppEigen.h>
#include <cli/progress.h>

double sigmoid(double x) {
return 1.0 / (1.0 + std::exp(-x));
Expand All @@ -21,8 +20,6 @@ SEXP dom_preds_calc(const Eigen::MatrixXd &beta_lm,

Eigen::MatrixXd result = Eigen::MatrixXd::Zero(J, B);

SEXP bar = PROTECT(cli_progress_bar(J, NULL));
cli_progress_set_format(bar, " - Estimating MSE {cli::pb_percent}");
for (int j = 0; j < J; ++j) {

Rcpp::List dmats_j = design_mats[j];
Expand All @@ -41,12 +38,9 @@ SEXP dom_preds_calc(const Eigen::MatrixXd &beta_lm,
Eigen::MatrixXd dom_preds_j = unit_preds_j.colwise().mean();
result.block(j, 0, 1, B) = dom_preds_j;

if (CLI_SHOULD_TICK) cli_progress_set(bar, j);

}
cli_progress_set_clear(bar, 1);
cli_progress_done(bar);
UNPROTECT(1);

return Rcpp::wrap(result);

}

0 comments on commit b257050

Please sign in to comment.