Perform the specified logical operation
on the character vector x
, recognising the
special strings "TRUE"
and "FALSE"
and treating other strings as logical variables.
verbalogic(x, op = "and")
Character vector.
Logical operation: one of the character strings
"and"
, "or"
or "not"
.
A character string.
This function performs simple logical operations on character strings that represent human-readable statements.
The character vector x
may contain any strings:
the special strings "TRUE"
and "FALSE"
are
treated as the logical values TRUE
and FALSE
,
while all other strings are treated as if they were
logical variables.
If op="and"
, the result is a single string,
logically equivalent to x[1] && x[2] && ... && x[n]
.
First, any entries of x
equal to "TRUE"
are removed.
The result is "FALSE"
if any of the entries of x
is "FALSE"
; otherwise it is equivalent to
paste(x, collapse=" and ")
.
If op="or"
, the result is a single string, logically equivalent to
x[1] || x[2] || ... || x[n]
.
First, any entries of x
equal to "FALSE"
are removed.
The result is "TRUE"
if any of the entries of x
is "TRUE"
; otherwise it is equivalent to
paste(x, collapse=" or ")
.
If op="not"
, the result is a character vector y
such that y[i]
is the logical negation of x[i]
.
The code does not understand English grammar and cannot expand logical expressions.
# NOT RUN {
x <- c("The sky is blue", "my name is not Einstein", "FALSE")
verbalogic(x, "and")
verbalogic(x, "or")
verbalogic(x, "not")
# }
Run the code above in your browser using DataLab