partialised provides a ‘partialised’ class that extends the partialising function of ‘purrr’ by making it easier to change the arguments. This is similar to the function-like object in ‘Julia’ (https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects).
You can install the development version of partialised from GitHub with:
# the released version from CRAN:
install.packages("partialised")
# the development version from GitHub:
# install.packages("devtools")
::install_github("UchidaMizuki/partialised") devtools
This is a basic example which shows you how to solve a common problem:
library(partialised)
<- function(x, y) {
dist sqrt(x ^ 2 + y ^ 2)
}
<- new_partialised(dist,
pdist list(x = 3))
pdist#> <partialised[1]>
#> function (x, y)
#> {
#> sqrt(x^2 + y^2)
#> }
#> (
#> x = 3
#> ...
#> )
pdist(y = 4)
#> [1] 5
arguments(pdist)
#> $x
#> [1] 3
$x
pdist#> [1] 3
$y
pdist#> NULL
$x <- 6
pdistpdist(y = 8)
#> [1] 10
$y <- 8
pdistpdist()
#> [1] 10