I have a function that I want to pass an operator to, like so:
foo <- function(a, b, op){
op(a, b)
}
foo(1, 2, `>`)
#> [1] FALSE
Created on 2020-07-31 by the reprex package (v0.3.0)
This is exactly what I want. My question is, can I achieve the same goal without the backticks? That is, so the function call would be
foo(1, 2, >)
I suppose this does not fully answer your question, but you can use magrittr
to avoid backsticks:
foo(a = 1, b = 2, op = is_less_than)
[1] TRUE
foo(a = 1, b = 2, op = is_greater_than)
[1] FALSE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With