1

I want to have a loop to retrieve data from this function listOMLRunEvaluations the function has a limit=10000. How can I make a loop in R to call this function either by task.id= i or by limit and offlimit (retrieve every 10000 rows in each iteration).

Bayan
  • 13
  • 2
  • 1
    Please make this question *reproducible*. This includes sample code (including listing non-base R packages), sample data (e.g., `dput(head(x))`), and expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Nov 06 '18 at 20:42

1 Answers1

0

You could use a for loop with Sys.sleep() in case you also have a limit of request per second:

result <- c()
for(i in 1:10) {
new <- listOMLRunEvaluations()
result <- c(old, new)
Sys.sleep(10)
}
gaut
  • 5,771
  • 1
  • 14
  • 45
  • 2
    Strongly recommend against the concept of building a response vector like this. I'd suggest rather you do something like `l <- lapply(1:10, function(i) ...)` and then `unlist(l)`: it may not be much faster in the smaller scale, but without this method larger-scale problems will gradually become slower as R has to reallocate and copy all data for `result` through each iteration. – r2evans Nov 06 '18 at 20:42
  • can you please explain more in using lapply in my functionlistOMLRunEvaluations @r2evans – Bayan Nov 13 '18 at 20:13
  • Bayan, I'm generally willing to help, but ... what is there for me to help with? Perhaps you mean `result <- unlist(lapply(1:n, function(ign) limitOMLRunEvaluations()))`? I know nothing about your process, if you present a reproducible question I might be able to provide more help. – r2evans Nov 13 '18 at 23:00