Printing from mclapply in R Studio

后端 未结 3 2165
迷失自我
迷失自我 2021-02-19 06:54

I am using mclapply from within RStudio and would like to have an output to the console from each process but this seems to be suppressed somehow (as mentioned for example here:

3条回答
  •  难免孤独
    2021-02-19 07:23

    Just expanding a little on the solution used by the asker, i.e. writing to a file to check progress:

    write.file = '/temp_output/R_progress'
    
    time1 = proc.time()[3]
    outstuff = unlist(mclapply(1:1000000, function(i){
      if (i %% 1000 == 0 ){
        file.create(write.file)
        fileConn<-file(write.file)
        writeLines(paste0(i,'/',nrow(loc),' ',(i/nrow(loc)*100)), fileConn)
        close(fileConn)
      }
      #do your stuff here
    }, mc.cores=6))
    print(proc.time()[3] - time1)
    

    And then you can monitor from a console with

    tail -c +0 -f '/temp_output/R_progress'

提交回复
热议问题