ipeaGIT / flightsbr

R Package to Download Flight and Airport Data from Brazil

Home Page:https://ipeagit.github.io/flightsbr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

single progress bar when downloading multiple months

rafapereirabr opened this issue · comments

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)
                      }
                   )