Progress bar in data.table aggregate action

前端 未结 2 546
遇见更好的自我
遇见更好的自我 2021-01-03 10:57

ddply has a .progress to get a progress bar while it\'s running, is there an equivalent for data.table in R?

2条回答
  •  孤独总比滥情好
    2021-01-03 11:54

    Following up on @jangorecki's excellent answer, here's a way to use a text progress bar:

    library(data.table)
    dt = data.table(a=1:4, b=c("a","b"))
    grpn = uniqueN(dt$b)
    pb <- txtProgressBar(min = 0, max = grpn, style = 3)
    dt[, {setTxtProgressBar(pb, .GRP); Sys.sleep(0.5); sum(a)}, b]
    close(pb)
    

提交回复
热议问题