rlang function for `is.function(res) || inherits(res,"formula")`

is there an existing function to test :

is.function(f) || inherits(f,"formula")

I tend to use this expression or to define my own when I need it too much but maybe it exists already in rlang ?

I searched here:


And found no use of inherits with 'formula' alone.

Your function looks straightforward enough, you should keep it in a utils.R file perhaps :slight_smile:

1 Like

Thanks! This made me discover inherits_any which is a nice improvement already :

inherits_any(f, c("function","formula"))
1 Like

You also have in rlang

  • is_function
  • is_formula
  • is_formulaish
  • is_lambda (to test if result of as_function)

those can be useful for such tests and better to just test for classes.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.