Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set encoding/fileEncoding option in readr/tidyverse? [duplicate]

i have a textfile of an old spectrometer. It is encoded in "UTF-16LE" (I found this out with the readr:guess_encoding() function). I managed to read it in in base-r with:

spectra_gr2 <-  read.csv("~/some/path/spectra.csv", header = F, encoding = "UTF-16LE", fileEncoding = "UTF-16LE",  skipNul = T)

This works fine, but i want to do it using tidyverse/readr! Does anyone know how i set the two options encoding/fileEncoding in read_delim() for Example?

like image 989
m4D_guY Avatar asked Nov 01 '25 02:11

m4D_guY


1 Answers

Use it in locale

readr::read_delim("~/some/path/spectra.csv", delim = ",",
       locale = readr::locale(encoding = "UTF-16LE"), col_names = FALSE)
like image 115
Ronak Shah Avatar answered Nov 03 '25 17:11

Ronak Shah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!