Running examples in ‘DeclareDesign-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: declare_estimator
> ### Title: Declare estimator
> ### Aliases: declare_estimator declare_estimators label_estimator
> ###   method_handler
> 
> ### ** Examples
> 
> 
> # Setup for examples
> design <-
+   declare_model(
+     N = 500,
+     gender = rbinom(N, 1, 0.5),
+     U = rnorm(N, sd = 0.25),
+     potential_outcomes(Y ~ rbinom(
+       N, 1, prob = pnorm(0.2 * Z + 0.2 * gender + 0.1 * Z * gender + U)
+     ))
+   ) +
+   declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
+   declare_sampling(S = complete_rs(N = N, n = 200)) +
+   declare_assignment(Z = complete_ra(N = N, m = 100)) +
+   declare_measurement(Y = reveal_outcomes(Y ~ Z))
>   
> run_design(design)
  inquiry estimand
1     ATE    0.138
> 
> # default estimator is lm_robust with tidy summary
> design_0 <-
+   design +
+   declare_estimator(Y ~ Z, inquiry = "ATE")
> 
> run_design(design_0)
  inquiry estimand estimator term estimate  std.error statistic   p.value
1     ATE    0.082 estimator    Z     0.01 0.07025926   0.14233 0.8869641
    conf.low conf.high  df outcome
1 -0.1285525 0.1485525 198       Y
> 
> # Linear regression using lm_robust and tidy summary
> design_1 <-
+   design +
+   declare_estimator(
+     formula = Y ~ Z,
+     .method = lm_robust,
+     .summary = tidy,
+     term = "Z",
+     inquiry = "ATE",
+     label = "lm_no_controls"
+   )
> 
> run_design(design_1)
  inquiry estimand term      estimator estimate  std.error statistic   p.value
1     ATE    0.106    Z lm_no_controls     0.01 0.06842381  0.146148 0.8839533
   conf.low conf.high  df outcome
1 -0.124933  0.144933 198       Y
> 
> # Use glance summary function to view model fit statistics
> design_2 <-
+   design +
+   declare_estimator(.method = lm_robust,
+                     formula = Y ~ Z,
+                     .summary = glance)
> 
> run_design(design_2)
  inquiry estimand estimator  r.squared adj.r.squared statistic   p.value
1     ATE    0.062 estimator 0.00490049 -0.0001252651 0.9750754 0.3246228
  df.residual nobs se_type
1         198  200     HC2
> 
> # Use declare_estimator to implement custom answer strategies
> my_estimator <- function(data) {
+   data.frame(estimate = mean(data$Y))
+ }
> 
> design_3 <-
+   design +
+   declare_inquiry(Y_bar = mean(Y)) +
+   declare_estimator(handler = label_estimator(my_estimator),
+                     label = "mean",
+                     inquiry = "Y_bar")
> 
> run_design(design_3)
  inquiry estimand estimator estimate
1   Y_bar    0.570      mean     0.57
2     ATE    0.136      <NA>       NA
> 
> # Use `term` to select particular coefficients
> design_4 <-
+   design +
+   declare_inquiry(difference_in_cates = mean(Y_Z_1[gender == 1] - Y_Z_0[gender == 1]) -
+                     mean(Y_Z_1[gender == 0] - Y_Z_0[gender == 0])) +
+   declare_estimator(Y ~ Z * gender,
+                     term = "Z:gender",
+                     inquiry = "difference_in_cates",
+                     .method = lm_robust)
> 
> run_design(design_4)
              inquiry  estimand     term estimator  estimate std.error
1 difference_in_cates 0.1443609 Z:gender estimator 0.1966622 0.1381796
2                 ATE 0.1180000     <NA>      <NA>        NA        NA
  statistic   p.value    conf.low conf.high  df outcome
1  1.423236 0.1562576 -0.07584754  0.469172 196       Y
2        NA        NA          NA        NA  NA    <NA>
> 
> # Use glm from base R
> design_5 <-
+   design +
+   declare_estimator(Y ~ Z + gender,
+                     family = "gaussian",
+                     inquiry = "ATE",
+                     .method = glm)
> 
> run_design(design_5)
  inquiry estimand estimator term estimate std.error statistic   p.value
1     ATE    0.074 estimator    Z     0.07      0.07         1 0.3185372
     conf.low conf.high
1 -0.06719748 0.2071975
> 
> # If we use logit, we'll need to estimate the average marginal effect with
> # margins::margins. We wrap this up in function we'll pass to model_summary
> 
> library(margins) # for margins
Error in library(margins) : there is no package called ‘margins’
Execution halted