ropensci / aRxiv
1
# make sure not to make calls too often
2

3
# get time of last call
4
get_arxiv_time <-
5
function()
6
{
7 1
   last <- as.numeric(Sys.getenv("aRxiv_time"))
8 1
   ifelse(is.na(last), 0, last)
9
}
10

11
# set arxiv time to current
12
set_arxiv_time <-
13
function() {
14 1
    Sys.setenv(aRxiv_time = as.numeric(Sys.time()))
15
}
16

17
# time since last call
18
time_since_arxiv <-
19
function() {
20 1
    as.numeric(Sys.time()) - get_arxiv_time()
21
}
22

23
# check for last time since call, and delay if necessary
24
# also re-set the arxiv_time
25
delay_if_necessary <-
26
function()
27
{
28
    # look for delay amount in options; otherwise set to default
29 1
    delay_amount <- getOption("aRxiv_delay")
30 0
    if(is.null(delay_amount)) delay_amount <- 3
31

32 1
    if((timesince = time_since_arxiv()) < delay_amount)
33 1
        Sys.sleep(delay_amount - timesince)
34

35 1
    set_arxiv_time()
36
}

Read our documentation on viewing source code .

Loading