[R] Following progress in a lapply() function

hadley wickham h.wickham at gmail.com
Mon Mar 23 00:15:58 CET 2009


On Sun, Mar 22, 2009 at 5:06 PM, Blanchette, Marco <MAB at stowers.org> wrote:
> Dear all,
>
> I am processing a very long and complicated list using lapply through a custom function and I would like to generate some sort of progress report. For instance, print a dot on the screen every time 1000 item have been process. Or even better, reporting the percent of the list that have been process every 10%. However, I can't seem to figure out a way to achieve that.
>
> For instance, I have a list of 50,000 slots:
>
> aList <- replicate(50000,list(rnorm(50)))
>
> That need to be process through the following custom function:
>
> myFnc <- function(x){
>     tTest <- t.test(x)
>    return(list(p.value=tTest$p.value,t.stat=tTest$stat))
> }
>
> Using an lapply statement, as in:
>
> myResults <- lapply(aList, myFnc)
>
> The goal would be to report on the progress of the lapply() function during processing.

install.packages("plyr")
library(plyr)

myResults <- llply(aList, myFnc, .progress = "text")

see http://had.co.nz/plyr for more info.

Hadley


-- 
http://had.co.nz/




More information about the R-help mailing list