Extract function name of a call

lang_name(lang)

Arguments

lang

Can be a call (language object), a formula quoting a call in the right-hand side, or a frame object from which to extract the call expression.

Value

A string with the function name, or NULL if the function is anonymous.

See also

lang_fn()

Examples

# Extract the function name from quoted calls: lang_name(~foo(bar))
#> [1] "foo"
lang_name(quote(foo(bar)))
#> [1] "foo"
# Or from a frame: foo <- function(bar) lang_name(call_frame()) foo(bar)
#> [1] "foo"
# Namespaced calls are correctly handled: lang_name(~base::matrix(baz))
#> [1] "matrix"
# Anonymous and subsetted functions return NULL: lang_name(~foo$bar())
#> NULL
lang_name(~foo[[bar]]())
#> NULL
lang_name(~foo()())
#> NULL