brackets: Extract information from a multi-value SOP/DNF expression

betweenBracketsR Documentation

Extract information from a multi-value SOP/DNF expression

Description

Functions to extract information from an expression written in SOP, or in the canonical DNF, for multi-value causal conditions. They extract either the values within brackets, or the causal condition names outside the brackets.

Arguments

x

A DNF/SOP expression.

type

Brackets type: curly, round or square.

invert

Logical, if activated returns whatever is not within the brackets.

outside

Logical, if activated returns the condition names outside the brackets.

regexp

Optional regular expression to extract information with.

expression

A DNF/SOP expression.

snames

A string containing the sets' names, separated by commas.

noflevels

Numerical vector containing the number of levels for each set.

simplify

Logical, remove redundant expressions after expansion.

Details

Expressions written in SOP are used in Boolean logic, signaling a disjunction of conjunctions.

These expressions are useful in Qualitative Comparative Analysis, a social science methodology used to search for causal configurations associated with a certain outcome.

They are also used to draw Venn diagrams with package venn, which draws any kind of set intersection based on a custom SOP expression.

curlyBrackets(), squareBrackets() and roundBrackets() are special cases of betweenBrackets() and outsideBrackets(), using curly, square or round brackets through the type argument.

outsideBrackets() can also be seen as a special case of betweenBrackets(invert = TRUE).

SOP expressions are usually written using curly brackets for multi-value conditions but, to allow evaluation of unquoted expressions through R's parser, unquoted expressions should use square brackets and conjunctions should always use the product * sign.

Sufficiency is recognized as "=>" in quoted expressions but this does not pass over R's parsing system in unquoted expressions. To overcome this problem, it is best to use the single arrow "->" notation. Necessity is recognized as either "<=" or "<-", both being valid in quoted and unquoted expressions.

Author(s)

Adrian Dusa

Examples

sop <- "A[1] + B[2]*C[0]"

betweenBrackets(sop)
betweenBrackets(sop, invert = TRUE)

# unquoted (valid) SOP expressions are allowed, same result
betweenBrackets(A[1] + B[2]*C[0])

# curly brackets are also valid in quoted expressions
betweenBrackets("A{1} + B{2}*C{0}", type = "{")
curlyBrackets("A{1} + B{2}*C{0}")
curlyBrackets("A{1} + B{2}*C{0}", outside = TRUE)

squareBrackets(A[1] + B[2]*C[0])
squareBrackets(A[1] + B[2]*C[0], outside = TRUE)


admisc documentation built on March 27, 2026, 9:06 a.m.

Related to brackets in admisc...