Runs a blueprint function where a condition is true, otherwise returns NA values

bp_where(condition, bp, ...)

Arguments

condition

Condition to check before evaluating. Results will be given where this is TRUE, and NA when this is FALSE

bp

Blueprint function to run based on the condition

...

arguments passed on to Blueprint, such as .seed

Value

a tibble

Examples

make_tbl <- blueprint( x = r_norm(), y = r_unif() ) set_n(10) i <- r_lgl() bp_where(i, make_tbl)
#> # A tibble: 10 x 2 #> x y #> <dbl> <dbl> #> 1 NA NA #> 2 NA NA #> 3 -0.00289 0.389 #> 4 NA NA #> 5 NA NA #> 6 0.413 0.461 #> 7 0.724 0.315 #> 8 NA NA #> 9 NA NA #> 10 2.35 0.175
df <- tibble::tibble( id = 1:10, cnd = r_lgl() ) dplyr::mutate(df, bp_where(cnd, make_tbl))
#> # A tibble: 10 x 4 #> id cnd x y #> <int> <lgl> <dbl> <dbl> #> 1 1 TRUE -0.424 0.466 #> 2 2 FALSE NA NA #> 3 3 TRUE -0.872 0.390 #> 4 4 FALSE NA NA #> 5 5 TRUE 0.107 0.0201 #> 6 6 FALSE NA NA #> 7 7 FALSE NA NA #> 8 8 TRUE -0.587 0.377 #> 9 9 FALSE NA NA #> 10 10 TRUE -0.328 0.560