Skip to contents

Expand statement containing wildcard

Usage

expand_wildcard(to_expand, join_by = "|", verbose = TRUE)

Arguments

to_expand

A character vector of length 1L.

join_by

A logical operator. Used to connect causal statements: AND ('&') or OR ('|'). Defaults to '|'.

verbose

Logical. Whether to print expanded query on the console.

Value

A character string with the expanded expression. Wildcard '.' is replaced by 0 and 1.

Examples


# Position of parentheses matters for type of expansion
# In the "global expansion" versions of the entire statement are joined
expand_wildcard('(Y[X=1, M=.] > Y[X=1, M=.])')
#> Generated expanded expression:
#> (Y[X=1, M=0] > Y[X=1, M=0] | Y[X=1, M=1] > Y[X=1, M=1])
#> [1] "(Y[X=1, M=0] > Y[X=1, M=0] | Y[X=1, M=1] > Y[X=1, M=1])"
# In the "local expansion" versions of indicated parts are joined
expand_wildcard('(Y[X=1, M=.]) > (Y[X=1, M=.])')
#> Generated expanded expression:
#> (Y[X=1, M=0] | Y[X=1, M=1]) > (Y[X=1, M=0] | Y[X=1, M=1])
#> [1] "(Y[X=1, M=0] | Y[X=1, M=1]) > (Y[X=1, M=0] | Y[X=1, M=1])"

# If parentheses are missing global expansion used.
expand_wildcard('Y[X=1, M=.] > Y[X=1, M=.]')
#> No parentheses indicated. Global expansion assumed. See expand_wildcard
#> Generated expanded expression:
#> Y[X=1, M=0] > Y[X=1, M=0] | Y[X=1, M=1] > Y[X=1, M=1]
#> [1] "Y[X=1, M=0] > Y[X=1, M=0] | Y[X=1, M=1] > Y[X=1, M=1]"

# Expressions not requiring expansion are allowed
expand_wildcard('(Y[X=1])')
#> Generated expanded expression:
#> (Y[X=1])
#> [1] "(Y[X=1])"