In terms of your question I'm having trouble imagining a scenario in which you would evaluate TRUE == "TRUE"
, vs "TRUE" == TRUE
. For instance; take a wrapper function that we can run all scenarios for your variables and iterate them through tests for as.logical, is.logical, x == TRUE, x == FALSE, x != TRUE
etc...
What our testing function will do is take an input and only return the scenarios that evaluate to TRUE
in terms of a logical test in an R function.
f <-function(var){
do_fun <- list(
`%s == TRUE` = function(x)x==TRUE,
`%s == FALSE` = function(x)x == FALSE,
`as.logical(%s)` = function(x)as.logical(x),
`is.logical(%s)` = function(x)is.logical(x))
a <- sapply(names(do_fun), function(i){
do.call(do_fun[[i]],list(var))
})
set_name <- sprintf(names(a),var)
a <- as.list(a)
names(a) <- set_name
a[sapply(a,`[`,1)]
}
Testing on TRUE
# from base test to show
> is.logical(TRUE)
[1] TRUE
Now with our testing fun
> f(TRUE)
$`TRUE == TRUE`
[1] TRUE
$`as.logical(TRUE)`
[1] TRUE
$`is.logical(TRUE)`
[1] TRUE
As strings instead of reserved characters
> f("true")
$`as.logical("true")`
[1] TRUE
> f("TRUE")
$`"TRUE" == TRUE`
[1] TRUE
$`as.logical("TRUE")`
[1] TRUE
On numeric values the output logical is based on the evaluation of the input rather than the class
> f(10.1)
$`as.logical(10.1)`
[1] TRUE
> f(10.1 > 1)
$`TRUE == TRUE`
[1] TRUE
$`as.logical(TRUE)`
[1] TRUE
$`is.logical(TRUE)`
[1] TRUE
or
> f(1+1)
$`as.logical(2)`
[1] TRUE