Skip to content

Instantly share code, notes, and snippets.

@AlbanSagouis
Last active May 20, 2025 07:14
Show Gist options
  • Select an option

  • Save AlbanSagouis/eec4a0866db0cb6a1f65271986d43af4 to your computer and use it in GitHub Desktop.

Select an option

Save AlbanSagouis/eec4a0866db0cb6a1f65271986d43af4 to your computer and use it in GitHub Desktop.
This simple function opens UTF-16 encoded delimited tables (such as Glonaf data) in R. Separator, decimal separator and other arguments can be passed to `data.table::fread` with `...`
read_utf16_table <- function(path, sep = "\t", ...) {
stringi::stri_read_lines(
con = path,
encoding = "UTF-16LE") |>
stringi::stri_join(collapse = "\n") |>
data.table::fread(sep = sep, ...)
}
@AngusMackenzie
Copy link

An elegant solution to an infuriating problem. Worked well, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment