Reputation: 1022
If I have a variable holding a string representation of a comparative operator such as:
> comparison <- "=="
how can I interpolate this string version of the binary operator between its operands? E.g.
> 2 <insert comparison> 2
TRUE
NB. I do not want to use mapply(get(comparison),2,2
since I intend to put 2 <insert comparison> 2
as an argument to which
.
Upvotes: 2
Views: 87
Reputation: 40861
I don't quite understand why you don't want to use mapply
, but do.call
is probably better anyway.
comparison <- "=="
do.call(comparison, list(2,2))
which( do.call(comparison, list(2,0:4)) )
Upvotes: 4