ipeaGIT / flightsbr

R Package to Download Flight and Airport Data from Brazil
https://ipeagit.github.io/flightsbr/
Other
41 stars 6 forks source link

single progress bar when downloading multiple months #6

Closed rafapereirabr closed 2 years ago

rafapereirabr commented 2 years ago

this can be done simply by replacing lapply with pbapply::pblapply. I'm not sure this is stricly necessary, and it adds a another package dependency.

original

dt_list <- lapply( X=all_months,
                   FUN= function(i, type.=type, showProgress.=showProgress, select.=select) { # i = all_months[3]

                      # prepare address of online data
                      split_date(i)
                      file_url <- get_url(type, year, month)

                      # download and read data
                      temp_dt <- download_flights_data(file_url, showProgress = showProgress, select = select)

                      # check if download failed
                      if (is.null(temp_dt)) { return(invisible(NULL)) }
                      return(temp_dt)
                      }
                   )

proposed

if( showProgress==FALSE){ pbapply::pboptions(type='none') }
if( showProgress==TRUE){ pbapply::pboptions(type='txt') }

dt_list <- pbapply::pblapply( X=all_months,
                   FUN= function(i, type.=type, showProgress.=FALSE, select.=select) { # i = all_months[3]

                      # prepare address of online data
                      split_date(i)
                      file_url <- get_url(type, year, month)

                      # download and read data
                      temp_dt <- download_flights_data(file_url, showProgress = FALSE, select = select)

                      # check if download failed
                      if (is.null(temp_dt)) { return(invisible(NULL)) }
                      return(temp_dt)
                      }
                   )