Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass an operator without backticks

Tags:

r

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, >)
like image 841
Lyngbakr Avatar asked Nov 06 '22 06:11

Lyngbakr


1 Answers

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
like image 160
tmfmnk Avatar answered Nov 15 '22 10:11

tmfmnk