Skip to content

[R-Forge #4903] set encoding in fread #563

Closed

Description

@arunsrinivasan

Submitted by: michele de meo; Assigned to: Nobody; R-Forge link

It's useful to specify the encoding before importing a csv.
For example:

fread(... , encoding='UTF8').

In this way we can avoid the boring use of file function in read.table (not supported in fread ):

read.table(file("mycsv.csm", encoding='UTF8'), ... ).

Michele De Meo

Activity

  1. EDiLD2 commented on Sep 24, 2014

    @EDiLD2

    +1 for this

  2. bnbwn commented on Nov 17, 2014

    @bnbwn

    +1

  3. stanasa commented on Dec 28, 2014

    @stanasa

    +1

  4. sirvydasdagys commented on Feb 11, 2015

    @sirvydasdagys

    +1

  5. harmonica2 commented on Mar 12, 2015

    @harmonica2

    +1

  6. zeltak commented on Mar 16, 2015

    @zeltak

    +1

  7. MarcinKosinski commented on Mar 16, 2015

    @MarcinKosinski

    +1

  8. grgurev commented on Mar 18, 2015

    @grgurev

    +1

  9. lucarno commented on Mar 24, 2015

    @lucarno

    +1

  10. seyedamo commented on Apr 9, 2015

    @seyedamo

    +1

  11. jcizel commented on Apr 9, 2015

    @jcizel

    +1

  12. Alectoria commented on Apr 13, 2015

    @Alectoria

    +1

  13. tophcito commented on Apr 16, 2015

    @tophcito

    +1

  14. clarkdk commented on Apr 29, 2015

    @clarkdk

    +1

  15. 8 remaining items

  16. panda2727 commented on Jun 17, 2015

    @panda2727

    +1

  17. duf59 commented on Aug 7, 2015

    @duf59

    +1

  18. romunov commented on Aug 7, 2015

    @romunov
    Contributor

    +1

    note however that in ?Encoding, UTF-8 is used (not UTF8).

  19. rentrop commented on Aug 22, 2015

    @rentrop

    +1

  20. leoluyi commented on Aug 24, 2015

    @leoluyi

    +1

  21. arunsrinivasan commented on Aug 25, 2015

    @arunsrinivasan
    MemberAuthor

    Tl;dr

    Could you please test your files with encoding = "UTF-8" or "Latin-1" and write back as to whether it solves the issue (especially on windows)? Thanks.


    About the fix:

    Looking at read.table() function, the encoding is set upfront with Encoding(..) <- .... And looking at the source of Encoding<-, it calls an internal function do_setencoding. Looking at the source of that function, https://github.com/wch/r-source/blob/ca5348f0b5e3f3c2b24851d7aff02de5217465eb/src/main/util.c#L1115, it seems quite straightforward to fix this (I think).. through the use of mkCharLenCE function that R's C-API seems to expose.

    fread() gains a new argument encoding with valid values unknown, UTF-8 and Latin-1. The default behaviour hasn't changed. Windows user will have to set the encoding argument explicitly. This could change in the future (perhaps also testing for performance hit would be a deciding factor).

  22. added a commit that references this issue on Aug 25, 2015
  23. added this to the v1.9.6 milestone on Aug 25, 2015
  24. clarkdk commented on Aug 31, 2015

    @clarkdk

    Arun, There's a typo in README.md

    27 . fread() gains eocnding argument. ... eocnding --> encoding

  25. jangorecki commented on Aug 31, 2015

    @jangorecki
    Member

    if speaking about the typos there is one missing () next to flush.console in bmerge function:

    if (verbose) {cat("done in",round(proc.time()[3]-last.started.at,3),"secs\n");flush.console}

  26. dbuijs commented on Sep 1, 2015

    @dbuijs

    Thank you for this!!!!

    A question of clarification: does the encoding option in fread just set the marked encoding, or does it convert from what you've declared to the system's native encoding?

  27. andreasio commented on Jun 21, 2016

    @andreasio

    I have an iso-8850-1 windows file, that I can't fread correctly on linux. This workaround (#563 (comment)) works. And read.csv works (i.e. produces the correct øæå letters, instead of e.g. \xe6), but fread(... encoding = "Latin-1") does not.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions