Could maybe explain what is the use of %>% in this particular function?
%>% is know as the pipe operator. Pipe operators have been used extensively in other languages (e.g. | in the shell). Pipes work by taking the left-hand side of the pipe and "piping" it into the function on the right-hand side.
Because of this "pass-it-on" property of pipes, you can chain together long sequences of pipes in order to pass some data along a pipeline for it to come out the other side transformed in some way you want. You can learn more about it here: https://magrittr.tidyverse.org/reference/pipe.html.
Pipes have gained so much favour in the R community thanks to the magrittr package, that they are being added into base R (look for |> as an alternative in the not-so-distant future).
In other words, if you have some variable x and functions f() and g(), you could write it two ways in R that both are equal:
# Pipe
x %>% f() %>% g()
# Nested
g(f(x))
The first one is executed left-to-right, while the latter is executed inside-out. Typically the first is easier to read, though both will produce identical results.
In my code x is an image as is being piped along, undergoing various transformations:
image_variance <- function(x) {
x %>%
as.raster() %>% # convert to array
as.vector() %>% # flatten to vector
map(col2rgb) %>% # Hex to RGB
map_dbl(function(rgb) (rgb[[1]]*0.3) + (rgb[[2]]*0.6) + (rgb[[3]]*0.1)) %>% # average color channels
var() # compute variance
}