Insert, delete and replace steps in an (already declared) design object.

insert_step(design, new_step, before, after)

delete_step(design, step)

replace_step(design, step, new_step)

Arguments

design

A design object, usually created using the + operator, expand_design, or the design library.

new_step

The new step; Either a function or a partial call.

before

The step before which to add steps.

after

The step after which to add steps.

step

The quoted label of the step to be deleted or replaced.

Value

A new design object.

Details

See modify_design for details.

Examples


 my_model <- 
   declare_model(
     N = 100, 
     U = rnorm(N),
     Y_Z_0 = U,
     Y_Z_1 = U + rnorm(N, mean = 2, sd = 2)
   )

 my_assignment <- declare_assignment(Z = complete_ra(N, m = 50))
 my_assignment_2 <- declare_assignment(Z = complete_ra(N, m = 25))

 design <- my_model + my_assignment

 design
#> 
#> Design Summary
#> 
#> Step 1 (model): declare_model(N = 100, U = rnorm(N), Y_Z_0 = U, Y_Z_1 = U + rnorm(N,     mean = 2, sd = 2)) 
#> 
#> N = 100 
#> 
#> Added variable: ID 
#>  N_missing N_unique     class
#>          0      100 character
#> 
#> Added variable: U 
#>    min median mean  max   sd N_missing N_unique
#>  -2.25  -0.02 0.03 2.39 0.96         0      100
#> 
#> Added variable: Y_Z_0 
#>    min median mean  max   sd N_missing N_unique
#>  -2.25  -0.02 0.03 2.39 0.96         0      100
#> 
#> Added variable: Y_Z_1 
#>    min median mean  max   sd N_missing N_unique
#>  -2.11   2.63 2.49 7.35 1.76         0      100
#> 
#> Step 2 (assignment): declare_assignment(Z = complete_ra(N, m = 50)) ------------
#> 
#> Added variable: Z 
#>     0    1
#>    50   50
#>  0.50 0.50
#> 
 
 if (FALSE) {
 insert_step(design, declare_step(dplyr::mutate, income = noise^2), 
             after = my_assignment)
 insert_step(design, declare_step(dplyr::mutate, income = noise^2), 
             before = my_assignment)
 

 # If you are using a design created by a designer, for example from
 #   the DesignLibrary package, you will not have access to the step
 #   objects. Instead, you can always use the label of the step.
 
 # get the labels for the steps
 names(design)
 
 insert_step(design, 
   declare_sampling(S = complete_rs(N, n = 50), 
   legacy = FALSE),
   after = "my_pop")
 }


 delete_step(design, my_assignment)
#> 
#> Design Summary
#> 
#> Step 1 (model): declare_model(N = 100, U = rnorm(N), Y_Z_0 = U, Y_Z_1 = U + rnorm(N,     mean = 2, sd = 2)) 
#> 
#> N = 100 
#> 
#> Added variable: ID 
#>  N_missing N_unique     class
#>          0      100 character
#> 
#> Added variable: U 
#>    min median  mean  max   sd N_missing N_unique
#>  -3.03   0.09 -0.01 2.53 1.02         0      100
#> 
#> Added variable: Y_Z_0 
#>    min median  mean  max   sd N_missing N_unique
#>  -3.03   0.09 -0.01 2.53 1.02         0      100
#> 
#> Added variable: Y_Z_1 
#>    min median mean  max   sd N_missing N_unique
#>  -2.52   1.56 1.92 7.81 2.14         0      100
#> 
 replace_step(design, my_assignment, declare_step(dplyr::mutate, words = "income"))
#> 
#> Design Summary
#> 
#> Step 1 (model): declare_model(N = 100, U = rnorm(N), Y_Z_0 = U, Y_Z_1 = U + rnorm(N,     mean = 2, sd = 2)) 
#> 
#> N = 100 
#> 
#> Added variable: ID 
#>  N_missing N_unique     class
#>          0      100 character
#> 
#> Added variable: U 
#>    min median mean max   sd N_missing N_unique
#>  -1.91  -0.05 0.04 2.5 0.94         0      100
#> 
#> Added variable: Y_Z_0 
#>    min median mean max   sd N_missing N_unique
#>  -1.91  -0.05 0.04 2.5 0.94         0      100
#> 
#> Added variable: Y_Z_1 
#>   min median mean  max   sd N_missing N_unique
#>  -3.3   2.33 2.01 7.67 2.44         0      100
#> 
#> Step 2 (custom): declare_step(dplyr::mutate, words = "income") -----------------
#> 
#> Added variable: words 
#>  income
#>     100
#>    1.00
#>