Hi,
The reason this is not working is because there is no loop in your function. If you like to get the results multiple times you need to specify a for-loop or while-loop.
The function tcl() might trigger ever x seconds, but this would not trigger the rest of the function around it again unless you are in a reactive environment like Shiny.
Here is an example how you could implement this
myData = data.frame()
for(x in 1:3){
print(paste("Start round", x))
newData = data.frame(x = x , time = Sys.time(), val = runif(1))
myData = rbind(myData, newData)
Sys.sleep(3)
}
#> [1] "Start round 1"
#> [1] "Start round 2"
#> [1] "Start round 3"
myData
#> x time val
#> 1 1 2021-02-07 09:19:25 0.8187054
#> 2 2 2021-02-07 09:19:28 0.3396553
#> 3 3 2021-02-07 09:19:31 0.1789086
Created on 2021-02-07 by the reprex package (v1.0.0)
In your case, do not set the timer within the function, but use the system sleep to wait before you run the next iteration.
Hope this helps,
PJ