Skip to contents

Returns the function name for simple calls (fn(x)), namespaced calls (pkg::fn(x), pkg:::fn(x)), and do.call() with a string literal first argument (do.call("fn", list(x))).

Usage

call_fn_name(expr)

Arguments

expr

A call expression.

Value

Character(1). The function name, or NA_character_ if it cannot be determined (e.g., anonymous function calls).

Examples

expr <- parse_code("mean(x)")[[1]]
call_fn_name(expr)
#> [1] "mean"

expr2 <- parse_code("stats::median(x)")[[1]]
call_fn_name(expr2)
#> [1] "stats::median"