How to add progress bar inside dplyr chain in R

后端 未结 2 1492
夕颜
夕颜 2021-02-07 09:36

I like dplyr\'s \"progress_estimated\" function but I can\'t figure out how to get a progress bar to work inside a dplyr chain. I\'ve put a reproducible example with code at the

2条回答
  •  無奈伤痛
    2021-02-07 10:07

    I dont really like my solution but it works.

    print_tick_function <- function(x, p) {
      p$tick()$print()
      data.frame(x)
    }
    
    SunriseSet <- function(dataframe, timezone){
      p <- progress_estimated(nrow(dataframe))
      dataframe %>% 
        rowwise() %>% 
        do(print_tick_function(.,p)) %>%
        mutate(
          datetime = as.POSIXct(substr(cdatetime, 1, 20), tz = timezone),
          sunrise = sunrise.set(latitude, longitude, datetime, timezone, num.days = 1)[1,1]
        )
    }
    test2 <- SunriseSet(test, "CST6CDT")
    

提交回复
热议问题