Wrapper to FOR loops with progress bar

前端 未结 8 676
走了就别回头了
走了就别回头了 2021-01-31 19:57

I like to use a progress bar while running slow for loops. This could be done easily with several helpers, but I do like the tkProgressBar from tcl

8条回答
  •  无人及你
    2021-01-31 20:28

    What you're hoping for, I think would be something that looks like

    body(for)<- as.call(c(as.name('{'),expression([your_updatebar], body(for))))
    

    And yep, the problem is that "for" is not a function, or at least not one whose "body" is accessible. You could, I suppose, create a "forp" function that takes as arguments 1) a string to be turned into the loop counter, e.g., " ( i in seq(1,101,5) )" , and 2) the body of your intended loop, e.g., y[i]<- foo[i]^2 ; points(foo[i],y[i], and then jump thru some getcallparse magic to execute the actual for loop. Then , in pseudocode (not close to actual R code, but I think you see what should happen)

    forp<-function(indexer,loopbody) { 
    

    pseudoparse( c("for (", indexer, ") {" ,loopbody,"}") }

提交回复
热议问题