readr::read_csv2() with UTF-16LE returning " R encountered a fatal error. The session was terminated".

I created a package in R that downloads and filters data from requests for access to information. The downloaded files are in CSV format with UTF-16LE encoding.

The package worked perfectly, but yesterday when trying to download data from 2022, the message appeared: "R encountered a fatal error. The session was terminated".

I tested the same function with the same parameters (but for other years) and it worked perfectly.

Apparently the problem is in the readr::read_csv2 function and the UTF-16LE encoding. When I download the file and change the encoding to UTF-8 (via notepad), it can read the file normally. But when it continues in UTF-16LE, it doesn't work.

Could anyone tell me why?

I have already updated R, RStudio and the packages involved.

Windows system config:
RStudio v2022.2.3 (have done uninstall, download, install)
R x64 v4.2.0 (have done uninstall, download, install)
Windows 10

install.packages('dail')

# works
q <- dail::requests(year = 2021, search = 'barragem')

# returns fatal error
q <- dail::requests(year = 2022, search = 'barragem')

Function inside the package with the error:

x <- readr::read_csv2(file = '20220604_Pedidos_csv_2022.csv', 
                      col_names = FALSE, 
                      col_types = cols(.default = "c"), 
                      quote = '\'', 
                      locale = readr::locale(encoding = "UTF-16LE"))

Thanks in advance!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.