From 46a47cf039c59faf72d488de04419fa773c2538d Mon Sep 17 00:00:00 2001 From: Alexander Coppock Date: Sat, 14 Nov 2026 21:47:00 -0600 Subject: [PATCH 1/3] Error at the call when a Suggests package is missing Helpers printed a message and returned NULL, so the failure surfaced later in unrelated code. rlang::check_installed() now stops at the call. Co-Authored-By: Claude Opus 5.5 --- R/helpers-causal-forests.R | 5 +---- R/helpers-conjoint-experiments.R | 5 +---- R/helpers-difference-in-differences.R | 5 +---- R/helpers-meta-analysis.R | 5 +---- R/helpers-multilevel-regression-poststratification.R | 5 +---- R/helpers-process-tracing.R | 5 +---- R/helpers-regression-discontinuity.R | 5 +---- R/helpers-stanreg.R | 5 +---- 8 files changed, 8 insertions(+), 32 deletions(-) diff --git a/R/helpers-causal-forests.R b/R/helpers-causal-forests.R index 11395f5..5aab0e2 100644 --- a/R/helpers-causal-forests.R +++ b/R/helpers-causal-forests.R @@ -36,10 +36,7 @@ #' causal_forest_handler <- function(data, covariate_names, share_train = 0.5, ...) { - if(!requireNamespace("grf")){ - message("The causal_forest_helper function requires the 'grf' package.") - return(invisible()) - } + rlang::check_installed("grf", reason = "to use `causal_forest_helper`.") X <- as.matrix(data %>% select(all_of(covariate_names))) diff --git a/R/helpers-conjoint-experiments.R b/R/helpers-conjoint-experiments.R index 3efd183..86a3adf 100644 --- a/R/helpers-conjoint-experiments.R +++ b/R/helpers-conjoint-experiments.R @@ -35,10 +35,7 @@ tidy.amce <- function(x, alpha = 0.05, ...) { - if(!requireNamespace("cjoint")){ - message("The tidy function for amce objects requires the 'cjoint' package.") - return(invisible()) - } + rlang::check_installed("cjoint", reason = "to use `tidy function for amce objects`.") z_score <- qnorm(1 - ((alpha) / 2)) summary_fit <- cjoint::summary.amce(x) diff --git a/R/helpers-difference-in-differences.R b/R/helpers-difference-in-differences.R index f3d73da..4381e16 100644 --- a/R/helpers-difference-in-differences.R +++ b/R/helpers-difference-in-differences.R @@ -76,10 +76,7 @@ lag_by_group <- function(x, groups, n = 1, order_by, default = NA) { #' did_multiplegt_tidy <- function(data, ...) { - if(!requireNamespace("DIDmultiplegt")){ - message("The did_multiplegt_tidy function requires the 'DIDmultiplegt' package.") - return(invisible()) - } + rlang::check_installed("DIDmultiplegt", reason = "to use `did_multiplegt_tidy`.") args <- list(...) if (identical(args$mode, "dyn") && is.null(args$graph_off)) { diff --git a/R/helpers-meta-analysis.R b/R/helpers-meta-analysis.R index 9523ed9..6ef821f 100644 --- a/R/helpers-meta-analysis.R +++ b/R/helpers-meta-analysis.R @@ -85,10 +85,7 @@ rma_mu_tau <- function(fit) { #' fit #' rma_helper <- function(data, yi, sei, method = "REML", ...){ - if(!requireNamespace("metafor")){ - message("The rma_helper function requires the 'metafor' package.") - return(invisible()) - } + rlang::check_installed("metafor", reason = "to use `rma_helper`.") fit <- try({metafor::rma(yi = data[[quo_text(enexpr(yi))]], sei = data[[quo_text(enexpr(sei))]], method = method, ... = ...)}) if(inherits(fit, "try-error")) { class(fit) <- c("rma.uni", "try-error") diff --git a/R/helpers-multilevel-regression-poststratification.R b/R/helpers-multilevel-regression-poststratification.R index 3aa15f3..eae8e45 100644 --- a/R/helpers-multilevel-regression-poststratification.R +++ b/R/helpers-multilevel-regression-poststratification.R @@ -34,10 +34,7 @@ #' post_stratification_helper <- function(model_fit, data, group, weights) { - if(!requireNamespace("marginaleffects")){ - message("The post_stratification_helper function requires the 'marginaleffects' package.") - return(invisible()) - } + rlang::check_installed("marginaleffects", reason = "to use `post_stratification_helper`.") # `re.form = NA` is an lme4 prediction argument. marginaleffects warns when # it is passed to a model that does not take it, so it goes only to a mixed diff --git a/R/helpers-process-tracing.R b/R/helpers-process-tracing.R index 66d0b43..674b349 100644 --- a/R/helpers-process-tracing.R +++ b/R/helpers-process-tracing.R @@ -31,10 +31,7 @@ process_tracing_estimator <- function(causal_model, query, data, strategies) { - if(!requireNamespace("CausalQueries")){ - message("The process_tracing_estimator function requires the 'CausalQueries' package.") - return(invisible()) - } + rlang::check_installed("CausalQueries", reason = "to use `process_tracing_estimator`.") if(nrow(data) !=1) { stop("please provide a single row dataset") diff --git a/R/helpers-regression-discontinuity.R b/R/helpers-regression-discontinuity.R index aab2e15..badeb43 100644 --- a/R/helpers-regression-discontinuity.R +++ b/R/helpers-regression-discontinuity.R @@ -20,10 +20,7 @@ #' tidy(fit) #' tidy.rdrobust <- function(x, ...) { - if(!requireNamespace("rdrobust")){ - message("The rdrobust_tidy function requires the 'rdrobust' package.") - return(invisible()) - } + rlang::check_installed("rdrobust", reason = "to use `rdrobust_tidy`.") ret <- data.frame(rownames(x$coef), x$coef, x$se, x$z, x$pv, x$ci, c = x$c) row.names(ret) <- NULL diff --git a/R/helpers-stanreg.R b/R/helpers-stanreg.R index b9245cd..e26fb13 100644 --- a/R/helpers-stanreg.R +++ b/R/helpers-stanreg.R @@ -29,10 +29,7 @@ tidy_stan <- function(x, conf.int = FALSE, conf.level = 0.95, exponentiate = FAL message("This function is deprecated. Please use the 'tidy' function from the 'broom.mixed' package.") - if(!requireNamespace("broom.mixed")){ - message("The tidy_stan function requires the 'broom.mixed' package.") - return(invisible()) - } + rlang::check_installed("broom.mixed", reason = "to use `tidy_stan`.") ret <- broom.mixed::tidy(x, conf.int = conf.int, conf.level = conf.level, exponentiate = exponentiate, ...) From f984842b97d5145edf154cfa691705105d486a5d Mon Sep 17 00:00:00 2001 From: Alexander Coppock Date: Sat, 14 Nov 2026 21:47:07 -0600 Subject: [PATCH 2/3] Reword cjoint reason Co-Authored-By: Claude Opus 5.5 --- R/helpers-conjoint-experiments.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/helpers-conjoint-experiments.R b/R/helpers-conjoint-experiments.R index 86a3adf..b48da2f 100644 --- a/R/helpers-conjoint-experiments.R +++ b/R/helpers-conjoint-experiments.R @@ -35,7 +35,7 @@ tidy.amce <- function(x, alpha = 0.05, ...) { - rlang::check_installed("cjoint", reason = "to use `tidy function for amce objects`.") + rlang::check_installed("cjoint", reason = "to use `tidy()` on an amce object.") z_score <- qnorm(1 - ((alpha) / 2)) summary_fit <- cjoint::summary.amce(x) From eb18cfa1335b0f834cf866e827f875a4ece24825 Mon Sep 17 00:00:00 2001 From: Alexander Coppock Date: Mon, 16 Nov 2026 15:27:29 -0600 Subject: [PATCH 3/3] Bump to development version; NEWS for the Suggests change Co-Authored-By: Claude Opus 5.5 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 60f4ec4..03a6edf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rdss Title: Companion Datasets and Functions for Research Design in the Social Sciences -Version: 1.0.16 +Version: 1.0.16.9000 Authors@R: c(person("Graeme", "Blair", email = "graeme.blair@gmail.com", role = c("aut"), comment = c(ORCID = "0000-0001-9164-2102")), person("Alexander", "Coppock", email = "acoppock@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-5733-2386")), diff --git a/NEWS.md b/NEWS.md index 9af62fe..f753809 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rdss (development version) + +* The eight helpers that wrap a Suggests package (`tidy_stan()`, `rdrobust_tidy()`, `process_tracing_estimator()`, `rma_helper()`, `did_multiplegt_tidy()`, `causal_forest_helper()`, `post_stratification_helper()`, and `tidy()` on an `amce` object) stop with an error naming the missing package, and offer to install it in an interactive session. They printed a message and returned `NULL` invisibly, so the failure surfaced later, in whatever code used the result. + # rdss 1.0.16 * In the GitHub version, `estimator_AS_tidy()` returns standard errors, p-values, and 95 percent confidence intervals. `interference::estimates()` computes effect variances only when told which condition is control, and rdss had never passed `control_condition`, so the variances were always empty. The Horvitz-Thompson rows use Aronow and Samii's conservative variance, the larger of the Horvitz-Thompson and constant-effects variances, since the plain Horvitz-Thompson variance of a difference can be negative. Intervals for an effect whose exposure condition is rare can undercover; the documentation gives the simulated rates.