R already has anonymous functions. Just write function(x) do_someting and you’re done. This post is for all of us who are not satisified with this solution. For one, it’s exhausting to write to long function(x) instead of, say, L(x), but that’s not all of it!
Take the following example, a calculation of the maximum likelihood estimate of a gamma distribution:
set.seed(313) x = rgamma(100, 2, 4) nlm(f = function(p) -mean(dgamma(x, shape = p, rate = p, log = TRUE)), p = c(1, 1))$estimate ##  2.