Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fread should exclude UTF-8 BOM from column names #1087

Closed
nigmastar opened this issue Mar 19, 2015 · 4 comments
Closed

Fread should exclude UTF-8 BOM from column names #1087

nigmastar opened this issue Mar 19, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@nigmastar
Copy link

Currently, fread seems to include the utf-8 BOM inside the file.

library(data.table)

# Create file

f <- "test_utf-8.csv"
cat(intToUtf8(c(239, 187, 191)), 'a,b,c\n1,2,3\n', file = f, sep = '')

# Import file

dt <- fread(f)
names(dt)
## [1] "a" "b"    "c"
@jangorecki
Copy link
Member

is there an easy workaround for that?

@httassadar
Copy link

Not sure if the issue title makes sense, why file names?

But the post does describe the issue I really hope it's fixed.

@nigmastar nigmastar changed the title Fread should exclude UTF-8 BOM from file names Fread should exclude UTF-8 BOM from column names Nov 12, 2015
@arunsrinivasan
Copy link
Member

The file you provide is incorrectly encoded.

> readBin("test_utf-8.csv", raw(), file.info("test_utf-8.csv")$size)
#  [1] c3 af c2 bb c2 bf 61 2c 62 2c 63 0a 31 2c 32 2c 33 0a

whereas it should be:

#  [1] ef bb bf 61 2c 62 2c 63 0a 31 2c 32 2c 33 0a

And performing fread("test_utf-8.csv") seems to work fine, although the BOM is still included:

ans = fread("test_utf-8.csv")
#    a b c
# 1: 1 2 3
charToRaw(names(ans)[1L])
# [1] ef bb bf 61

@arunsrinivasan
Copy link
Member

With this fix, now I get:

charToRaw(names(ans)[1L])
# [1] 61

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Mar 7, 2016
@arunsrinivasan arunsrinivasan self-assigned this Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants