@@ -475,13 +475,13 @@ overlay_function <- function(...) {
475475# Resolve a function name and store the expression passed in by the user
476476# ' @noRd
477477# ' @param f a function-like thing: a string naming a function, a function
478- # ' object, an anonymous function object, and `NULL`.
478+ # ' object, an anonymous function object, a formula-based lambda, and `NULL`.
479479# ' @param fallback character string providing a fallback function name
480480# ' @return the function named in `f` with an added `"tagged_expr"` attribute
481481# ' containing the expression to represent the function name and an
482482# ' `"is_anonymous_function"` attribute to flag if the expression is a call to
483483# ' `function()`.
484- as_tagged_function <- function (f , fallback = " func" ) {
484+ as_tagged_function <- function (f = NULL , fallback = " func" ) {
485485 qf <- enquo(f )
486486 f <- eval_tidy(qf )
487487 if (! is.null(attr(f , " tagged_expr" ))) return (f )
@@ -490,17 +490,17 @@ as_tagged_function <- function(f, fallback = "func") {
490490 f_fn <- f
491491
492492 if (rlang :: is_character(f )) { # f = "mean"
493- # using sym() on the evaluated `f` that a variable that names a
493+ # using sym() on the evaluated `f` means that a variable that names a
494494 # function string `x <- "mean"; as_tagged_function(x)` will be lost
495- # but that seems okay!
495+ # but that seems okay
496496 f_expr <- rlang :: sym(f )
497497 f_fn <- match.fun(f )
498498 } else if (is_null(f )) { # f = NULL
499499 f_fn <- identity
500500 f_expr <- rlang :: sym(fallback )
501501 } else if (is_callable(f )) { # f = mean or f = function(x) mean(x)
502- f_expr <- f_expr
503- f_fn <- f
502+ f_expr <- f_expr # or f = ~mean(.x)
503+ f_fn <- as_function( f )
504504 }
505505
506506 # Setting attributes on primitive functions is deprecated, so wrap them
@@ -512,7 +512,8 @@ as_tagged_function <- function(f, fallback = "func") {
512512 }
513513
514514 attr(f_fn , " tagged_expr" ) <- f_expr
515- attr(f_fn , " is_anonymous_function" ) <- is_call(f_expr , name = " function" )
515+ attr(f_fn , " is_anonymous_function" ) <- is_call(f_expr , name = " function" ) ||
516+ is_formula(f_expr )
516517 f_fn
517518}
518519
0 commit comments