R Currying & Partial Application: purrr::partial() & rlang
Partial application fixes some arguments of a function, returning a new function that takes the rest. Currying transforms a multi-argument function into a chain of single-argument functions. Both reduce repetition in functional R code.
When you call mean(x, na.rm = TRUE) over and over, partial application lets you create safe_mean <- partial(mean, na.rm = TRUE) so you only write safe_mean(x).
**Explanation:** `partial()` pre-fills `level` and `timestamp`, leaving only `msg` for the caller. This eliminates repeated boilerplate arguments.
Summary
Tool
Package
Use
partial(f, ...)
purrr
Fix some arguments of f
Closure function(x) f(x, fixed)
base
Manual partial application
Curried f(a)(b)(c)
manual
Chain of single-arg functions
FAQ
Is partial application the same as default arguments?
No. Default arguments are set in the function definition and can be overridden by any caller. Partial application creates a new function where certain arguments are permanently fixed. The caller of the partially applied function can't change them (without accessing the closure).
Does R have a built-in curry function?
No. R doesn't have a built-in curry function. You can implement one manually or use functional::Curry() from the functional package. In practice, partial application with purrr::partial() is more useful in R than currying.