Programming with lapply

March 31, 2022 at 9 PM

TIL that lapply accepts both functions and function names (as character vectors). From right there in the documentation (emph. mine):

FUN is found by a call to and typically is specified as a function or a symbol (e.g., a backquoted name) or a character string specifying a function to be searched for from the environment of the call to lapply.

So, lapply can use to find and apply our functions directly; no need to hack around when we need custom function application. That’s way simpler in cases like we’ve just had recently at work, where we need to apply one of a variety of functions depending on the program’s state.

Related Posts