Solveddata.table fwrite UTF8

Hello

Could you please add an option to fwrite in order to choose the character encoding, please?
Such as UTF-8.
I know already that fread has that option.

16 Answers

✔️Accepted Answer

Having encoding issues in Windows. Windows encoding is a real pain

+1

Other Answers:

Personally, I don't think having "UTF-8" by default is a good idea. Everybody here understand enough encoding to use it, however most people do not. I'm thinking about my french fellows that will fwrite a file and try to read it again to see all their accents become:

            v1 v2
 1:     Parler  1
 2:  français  2
 3:         Ã   3
 4:    Québec  4
 5:       dans  5
 6:         un  6
 7:     hôtel  7
 8:     amène  8
 9:        son  9
10:        lot 10
11:         de 11
12: problèmes 12

They will have to troubleshot and it's bad for beginners. Most people want there encoding to be default to their system. Few actually have both windows and Linux, or share file between Linux or windows. What we really need is an option that allows us to decide if we want a least either system encoding or utf8.

For the RE, I created something basic:

# a table that would cause trouble for encoding
dd <- data.frame(v1 = c("Parler", "français", "à", "Québec", "dans", "un",
                   "hôtel", "amène", "son", "lot", "de", "problèmes"),
                 v2 = 1:12)

library(data.table)

# the basic fwrite
fwrite(dd, "desktop/crap/ex_fwrite_win.csv")

# the equivalent base R
write.table(dd, "desktop/crap/ex_writetable_win.csv",
            sep=";", col.names = T, row.names = F, quote=F)

# The base R function that we want in fwrite
write.table(dd, "desktop/crap/ex_writetable_win_utf8.csv",
            sep=";", col.names = T, row.names = F, quote=F, fileEncoding = "UTF-8")

# What would happen to somebody that is clueless about encoding if default fwrite encoding on fwrite would be utf8
fread("desktop/crap/ex_writetable_win_utf8.csv")

Related Issues:

11
data.table Compatibility with the future native pipe
(FWIW the tidyverse team are planning to work with R core to figure out a placeholder syntax (or equ...
6
data.table memory leak
Markus: I shouldn't have written RAM usage What I had in mind more specifically was cache not RAM My...
3
data.table fwrite(): final items
Do people actually like having quote=TRUE when writing to csv? I find it to be a big nuisance and wo...
3
data.table fwrite UTF8
Having encoding issues in Windows Windows encoding is a real pain +1 Hello Could you please add an o...
3
data.table Error when installing from source on macOS
Never mind I figured it out and am able to install with multithreaded support I had to change my .R/...