Assuming that one is looking to pin an online resource that is typically
updated at the same time each day, this function calculates a refresh
interval that maximizes the likelihood that a pin is refreshed close to the
time the new version "drops" (the drop_hour
).
The assumption is that the resource drops sometime between drop_hour
and
drop_hour + drop_window
. During that time, the refresh interval is lowered
to refresh_floor
. After the drop window closes, the interval slowly rises
to refresh_ceiling
, in a way that ensures that a refresh is always
triggered if a resource has not been refreshed after the last drop window
closed.
Usage
gp_dropper(
drop_hour,
drop_window = 1,
drop_tz = Sys.timezone(),
refresh_floor = 0.1,
refresh_ceiling = 12,
now_hour = Sys.time()
)
Arguments
- drop_hour
The hour at which the resource typically drops. Either specified as a numeric in 24h time, or as a POSIX time object.
- drop_window
The window, in hours, during the time we expect the drop to happen.
- drop_tz
The time zone of the resource. In particular, this is relevant if the
drop_hour
is specified as a number, butnow_hour
is specified as a POSIX time object.- refresh_floor
The lowest allowed refresh interval.
- refresh_ceiling
The highest allowed refresh interval.
- now_hour
The hour at which the pin is taking place. Can be passed as a numeric in 24h time, or as a POSIX time. Defaults to current time, which is often appropriate.
Examples
# Assuming that the resource is updated at noon, US/Eastern time zone
url <- "https://vincentarelbundock.github.io/Rdatasets/csv/openintro/country_iso.csv"
pin(url, refresh_hours = gp_dropper(drop_hour = 12, drop_tz = "US/Eastern"))
#> pin() downloaded fresh version ...
#> [1] "/home/runner/work/gitpins/gitpins/gitpins/5ad1e570044be11330713642c682b9db.data"
# Demonstration of the actual refresh interval returned by gp_dropper()
gp_dropper(drop_hour = 12, drop_tz = "US/Eastern")
#> [1] 2.149476