Skip to content

read_flights() fails for July 2025 (202507) with “invalid multibyte string” #51

Description

@flaviogckessler

Description

flightsbr::read_flights() fails when reading the flight data for July 2025 (date = 202507) with the following error:

Error in nchar(msg) : invalid multibyte string, element 1

The problem appears to be specific to the July 2025 dataset. Reading the complete 2024 dataset works normally, and testing the 2025 data month by month isolated the error to 202507.

Reproducible example

flight_cols <- c(
  "id_empresa",
  "nr_voo",
  "dt_partida_real",
  "sg_iata_origem",
  "sg_iata_destino"
)

flights_202507 <- flightsbr::read_flights(
  date = 202507,
  showProgress = FALSE,
  select = flight_cols,
  cache = FALSE
)

Error

Error in nchar(msg) : invalid multibyte string, element 1

Additional tests

Reading the complete 2024 dataset works without errors:

flights_2024 <- flightsbr::read_flights(
  date = 2024,
  showProgress = FALSE,
  select = flight_cols,
  cache = FALSE
)

I also tested each month of 2025 separately:

months_2025 <- as.integer(sprintf("2025%02d", 1:12))

results_2025 <- setNames(
  lapply(months_2025, function(month) {
    message("Testing ", month)

    tryCatch(
      {
        data <- flightsbr::read_flights(
          date = month,
          showProgress = FALSE,
          select = flight_cols,
          cache = FALSE
        )

        list(
          data = data,
          error = NA_character_
        )
      },
      error = function(e) {
        list(
          data = NULL,
          error = conditionMessage(e)
        )
      }
    )
  }),
  months_2025
)

The error was isolated to:

date = 202507

I then removed nr_voo from the selected columns to determine whether its automatic numeric conversion was responsible:

flight_cols_without_nr_voo <- setdiff(
  flight_cols,
  "nr_voo"
)

flights_202507 <- flightsbr::read_flights(
  date = 202507,
  showProgress = FALSE,
  select = flight_cols_without_nr_voo,
  cache = FALSE
)

The same error still occurred:

Error in nchar(msg) : invalid multibyte string, element 1

Therefore, the problem does not appear to be limited to the nr_voo column or its numeric conversion.

I also tested the following:

  • Updated flightsbr to version 1.1.1.
  • Updated curl to version 7.1.0.
  • Disabled the download progress display with showProgress = FALSE.
  • Disabled the cache with cache = FALSE.
  • Confirmed that the character locale is UTF-8.
Sys.getlocale("LC_CTYPE")

Output:

"Portuguese_Brazil.utf8"

Expected behavior

The July 2025 flight data should be downloaded and imported in the same way as the other monthly datasets.

Actual behavior

The import stops with the following error:

Error in nchar(msg) : invalid multibyte string, element 1

Possible source of the problem

Because changing the selected columns does not affect the result, the error may occur before or during the import of the selected columns, possibly while:

  • processing the downloaded ZIP archive;
  • handling the filename or metadata stored in the archive;
  • extracting the July 2025 file; or
  • processing a malformed character in the source file.

This is only a hypothesis. I have not identified the exact internal operation causing the error.

Package versions

packageVersion("flightsbr")
packageVersion("curl")
packageVersion("archive")
packageVersion("data.table")

Output:

[1] ‘1.1.1’
[1] ‘7.1.0’
[1] ‘1.1.13’
[1] ‘1.18.4’

Session information

sessionInfo()

Output:

R version 4.6.1 (2026-06-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26200)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8
[2] LC_CTYPE=Portuguese_Brazil.utf8
[3] LC_MONETARY=Portuguese_Brazil.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=Portuguese_Brazil.utf8

time zone: America/Sao_Paulo
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] archive_1.1.13
[2] rnaturalearth_1.2.0
[3] sf_1.1-1
[4] dplyr_1.2.1
[5] airportr_0.1.3
[6] ggplot2_4.0.3
[7] data.table_1.18.4
[8] flightsbr_1.1.1

loaded via a namespace (and not attached):
 [1] generics_0.1.4     class_7.3-23       xml2_1.6.0
 [4] KernSmooth_2.23-26 stringi_1.8.7      digest_0.6.39
 [7] magrittr_2.0.5     evaluate_1.0.5     grid_4.6.1
[10] timechange_0.4.0   RColorBrewer_1.1-3 fastmap_1.2.0
[13] e1071_1.7-17       DBI_1.3.0          httr_1.4.8
[16] rvest_1.0.5        selectr_0.6-0      scales_1.4.0
[19] cli_3.6.6          rlang_1.3.0        units_1.0-1
[22] withr_3.0.3        yaml_2.3.12        tools_4.6.1
[25] curl_7.1.0         vctrs_0.7.3        R6_2.6.1
[28] proxy_0.4-29       lifecycle_1.0.5    lubridate_1.9.5
[31] classInt_0.4-11    stringr_1.6.0      snakecase_0.11.1
[34] fs_2.1.0           janitor_2.2.1      pkgconfig_2.0.3
[37] pillar_1.11.1      gtable_0.3.6       glue_1.8.1
[40] Rcpp_1.1.2         xfun_0.60          tibble_3.3.1
[43] tidyselect_1.2.1   knitr_1.51         farver_2.1.2
[46] htmltools_0.5.9    rmarkdown_2.31     compiler_4.6.1
[49] S7_0.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions