Progression Handler: Progress Reported via a User-Defined Hook Function
Source:R/handler_callback.R
handler_callback.RdA progression handler that calls a custom hook function every time this handler receives a progression update, e.g. to forward progress information to logging, GUIs, or other external systems not supported by progressr.
Usage
handler_callback(
fcn = NULL,
intrusiveness = getOption("progressr.intrusiveness.callback", 1),
target = "callback",
...
)Arguments
- fcn
(function) A hook function that is called whenever this handler reports on an
"initiate","update", or"finish"event. It is called asfcn(type, step, max_steps, message, amount), wheretype(character string) is one of"initiate","update", or"finish",step(integer) is the number of steps completed so far,max_steps(integer) is the total number of steps,message(character string) is the latest progress message, andamount(numeric) is the increment instepsince the previous call. The function should accept...to remain forward compatible with future arguments. Any value returned byfcnis ignored. IfNULL(default), no hook function is called, i.e. this handler produces no output.- intrusiveness
(numeric) A non-negative scalar on how intrusive (disruptive) the reporter to the user.
- target
(character vector) Specifies where progression updates are rendered.
- ...
Additional arguments passed to
make_progression_handler().
Value
A function of class progression_handler that takes a
progression condition as its first and only argument.
Examples
handlers(handler_callback(fcn = function(type, step, max_steps, message, amount, ...) {
message(sprintf("[%s] step %d/%d (%+g): %s", type, step, max_steps, amount, message))
}))
with_progress({ y <- slow_sum_p(1:10) })
#> M: Added value 1
#> M: Added value 2
#> M: Added value 3
#> M: Added value 4
#> M: Added value 5
#> M: Added value 6
#> M: Added value 7
#> M: Added value 8
#> M: Added value 9
#> M: Added value 10
print(y)
#> [1] 55