gov_init {governor} | R Documentation |
Initialize a governor to control the speed of a loop
gov_init(interval, alpha = 0.4, alpha_decay = 0.95, alpha_target = 0.05)
interval |
desired interval in seconds E.g. |
alpha |
initial learning rate used to adjust wait time. Default: 0.4 |
alpha_decay |
rate at which alpha decays. Default: 0.95 i.e. 5 each iteration |
alpha_target |
the baseline alpha to reach when running long term. default: 0.05 |
gov object to be used with gov_wait()
# This loop should take approx 1 second as the governor will limit
# the loop to run every thirtieth of a second.
gov <- gov_init(1/30)
system.time({
for (i in 1:30) {
gov_wait(gov)
}
})