{
  "id": 9830,
  "title": "More Russian Encoding Issues with R on Windows",
  "url": "/competitions/avito-prohibited-content/discussion/9830",
  "author_name": "",
  "post_date": "2014-07-21T13:07:11.147Z",
  "votes": null,
  "comment_count": 2,
  "views": 1675,
  "content": "<p>I have asked the following question on StackOverflow, but no one has been able to provide any insight. &nbsp;I wanted to post it here as well since others may have come across this issue:</p>\n<p><a href=\"http://stackoverflow.com/questions/24830574/output-not-being-encoded-consistently\">http://stackoverflow.com/questions/24830574/output-not-being-encoded-consistently</a></p>\n<p>If I write head(output) my text is not encoded properly (as shown above) whereas if I simply write output$Title[0:3] it will display the text correctly like so:</p>\n<p><code>&gt; output$Title[0:3]<br>[[1]]<br>[1] &quot;Renault Logan, 2005&quot;</code><code>[[2]]<br>[1] &quot;&#1057;&#1082;&#1083;&#1072;&#1076;&#1089;&#1082;&#1086;&#1077; &#1087;&#1086;&#1084;&#1077;&#1097;&#1077;&#1085;&#1080;&#1077;, 345 &#1084;&#178;&quot;</code><code>[[3]]<br>[1] &quot;&#1057;&#1091;-&#1096;&#1077;&#1092;&quot;</code></p>\n<p>However, if I write:</p>\n<p><code>&gt; head(output)<br> Id Title IsProhibited<br>1 10000074 Renault Logan, 2005 0<br>2 10000124 &#209;&#234;&#235;&#224;&#228;&#241;&#234;&#238;&#229; &#239;&#238;&#236;&#229;&#249;&#229;&#237;&#232;&#229;, 345 &#236;&lt;U+00B2&gt; 0<br>3 10000175 &#209;&#243;-&#248;&#229;&#244; 0<br>4 10000196 3-&#234; &#234;&#226;&#224;&#240;&#242;&#232;&#240;&#224;, 64 &#236;&lt;U+00B2&gt;, 3/5 &#253;&#242;. 0<br>5 10000387 Samsung galaxy S4 mini GT-I9190 (&#247;&#184;&#240;&#237;&#251;&#233;) 0<br>6 10000395 &#202;&#224;&#240;&#242;&#232;&#237;&#224; &#202;&#240;&#251;&#236;. &#207;&#238;&#241;&#229;&#235;&#238;&#234; &#192;&#240;&#238;&#236;&#224;&#242; (&#245;&#238;&#235;&#241;&#242;, &#236;&#224;&#241;&#235;&#238;) 0</code></p>\n<p>Or if I try to write to a CSV (using write.table) the output is not encoded properly (as shown above).</p>\n<p>Here is a sample of my data for a reproducible example:</p>\n<p><code># create test data<br>test &lt;- structure(list(Id = c(10000074L, 10000124L, 10000175L, 10000196L, <br> 10000387L, 10000395L), Title = c(&quot;Zeit 9-25 &#1082;&#1075; &#1085;&#1086;&#1074;&#1099;&#1077; &#1072;&#1074;&#1090;&#1086;&#1082;&#1088;&#1077;&#1089;&#1083;&#1072;&quot;, &quot;2-&#1082; &#1082;&#1074;&#1072;&#1088;&#1090;&#1080;&#1088;&#1072;, 55 &#1084;&#178;, 1 &#1101;&#1090;.&quot;, <br> &quot;&#1044;&#1086;&#1089;&#1090;&#1086;&#1081;&#1085;&#1072;&#1103; &#1088;&#1072;&#1073;&#1086;&#1090;&#1072;&quot;, &quot;&#1042;&#1040;&#1047; 2106, 1994&quot;, &quot;&#1042;&#1086;&#1076;&#1080;&#1090;&#1077;&#1083;&#1100; &#1089; &#1083;&#1080;&#1095;&#1085;&#1099;&#1084; &#1072;/&#1084; &#1043;&#1072;&#1079;&#1077;&#1083;&#1100;&quot;, <br> &quot;&#1050;&#1086;&#1084;&#1085;&#1072;&#1090;&#1072; 45 &#1084;&#178; &#1074; 1-&#1082;, 3/14 &#1101;&#1090;.&quot;), IsProhibited = structure(c(1L, <br> 1L, 1L, 1L, 1L, 1L), .Label = c(&quot;0&quot;, &quot;1&quot;), class = &quot;factor&quot;)), .Names = c(&quot;Id&quot;, <br> &quot;Title&quot;, &quot;IsProhibited&quot;), row.names = c(NA, 6L), class = &quot;data.frame&quot;)</code></p>\n<p><code># outputs correctly as Russian characters<br>output$Title[0:6]</code></p>\n<p><code># but, why do the same rows output incorrectly <br># when using head() or write.table()?<br>head(test)</code></p>\n<p>How can I get my data to be output correctly?</p>\n<p>Note: I have set my encoding like so:</p>\n<p><code>Sys.setlocale(&quot;LC_CTYPE&quot;, &quot;russian&quot;) # set locale for Russian encoding...</code></p>",
  "messages": [
    {
      "id": "51008",
      "postDate": "07/21/2014 13:07:11",
      "content": "<p>I have asked the following question on StackOverflow, but no one has been able to provide any insight. &nbsp;I wanted to post it here as well since others may have come across this issue:</p>\n<p><a href=\"http://stackoverflow.com/questions/24830574/output-not-being-encoded-consistently\">http://stackoverflow.com/questions/24830574/output-not-being-encoded-consistently</a></p>\n<p>If I write head(output) my text is not encoded properly (as shown above) whereas if I simply write output$Title[0:3] it will display the text correctly like so:</p>\n<p><code>&gt; output$Title[0:3]<br>[[1]]<br>[1] &quot;Renault Logan, 2005&quot;</code><code>[[2]]<br>[1] &quot;&#1057;&#1082;&#1083;&#1072;&#1076;&#1089;&#1082;&#1086;&#1077; &#1087;&#1086;&#1084;&#1077;&#1097;&#1077;&#1085;&#1080;&#1077;, 345 &#1084;&#178;&quot;</code><code>[[3]]<br>[1] &quot;&#1057;&#1091;-&#1096;&#1077;&#1092;&quot;</code></p>\n<p>However, if I write:</p>\n<p><code>&gt; head(output)<br> Id Title IsProhibited<br>1 10000074 Renault Logan, 2005 0<br>2 10000124 &#209;&#234;&#235;&#224;&#228;&#241;&#234;&#238;&#229; &#239;&#238;&#236;&#229;&#249;&#229;&#237;&#232;&#229;, 345 &#236;&lt;U+00B2&gt; 0<br>3 10000175 &#209;&#243;-&#248;&#229;&#244; 0<br>4 10000196 3-&#234; &#234;&#226;&#224;&#240;&#242;&#232;&#240;&#224;, 64 &#236;&lt;U+00B2&gt;, 3/5 &#253;&#242;. 0<br>5 10000387 Samsung galaxy S4 mini GT-I9190 (&#247;&#184;&#240;&#237;&#251;&#233;) 0<br>6 10000395 &#202;&#224;&#240;&#242;&#232;&#237;&#224; &#202;&#240;&#251;&#236;. &#207;&#238;&#241;&#229;&#235;&#238;&#234; &#192;&#240;&#238;&#236;&#224;&#242; (&#245;&#238;&#235;&#241;&#242;, &#236;&#224;&#241;&#235;&#238;) 0</code></p>\n<p>Or if I try to write to a CSV (using write.table) the output is not encoded properly (as shown above).</p>\n<p>Here is a sample of my data for a reproducible example:</p>\n<p><code># create test data<br>test &lt;- structure(list(Id = c(10000074L, 10000124L, 10000175L, 10000196L, <br> 10000387L, 10000395L), Title = c(&quot;Zeit 9-25 &#1082;&#1075; &#1085;&#1086;&#1074;&#1099;&#1077; &#1072;&#1074;&#1090;&#1086;&#1082;&#1088;&#1077;&#1089;&#1083;&#1072;&quot;, &quot;2-&#1082; &#1082;&#1074;&#1072;&#1088;&#1090;&#1080;&#1088;&#1072;, 55 &#1084;&#178;, 1 &#1101;&#1090;.&quot;, <br> &quot;&#1044;&#1086;&#1089;&#1090;&#1086;&#1081;&#1085;&#1072;&#1103; &#1088;&#1072;&#1073;&#1086;&#1090;&#1072;&quot;, &quot;&#1042;&#1040;&#1047; 2106, 1994&quot;, &quot;&#1042;&#1086;&#1076;&#1080;&#1090;&#1077;&#1083;&#1100; &#1089; &#1083;&#1080;&#1095;&#1085;&#1099;&#1084; &#1072;/&#1084; &#1043;&#1072;&#1079;&#1077;&#1083;&#1100;&quot;, <br> &quot;&#1050;&#1086;&#1084;&#1085;&#1072;&#1090;&#1072; 45 &#1084;&#178; &#1074; 1-&#1082;, 3/14 &#1101;&#1090;.&quot;), IsProhibited = structure(c(1L, <br> 1L, 1L, 1L, 1L, 1L), .Label = c(&quot;0&quot;, &quot;1&quot;), class = &quot;factor&quot;)), .Names = c(&quot;Id&quot;, <br> &quot;Title&quot;, &quot;IsProhibited&quot;), row.names = c(NA, 6L), class = &quot;data.frame&quot;)</code></p>\n<p><code># outputs correctly as Russian characters<br>output$Title[0:6]</code></p>\n<p><code># but, why do the same rows output incorrectly <br># when using head() or write.table()?<br>head(test)</code></p>\n<p>How can I get my data to be output correctly?</p>\n<p>Note: I have set my encoding like so:</p>\n<p><code>Sys.setlocale(&quot;LC_CTYPE&quot;, &quot;russian&quot;) # set locale for Russian encoding...</code></p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51014",
      "postDate": "07/21/2014 17:00:07",
      "content": "<p>It may be related to Windows operating system (or Windows version of R). Namely, I also managed to display data correctly. However only if I limited loading of data to first few hundred records (after then comes some unicode that my R version cannot handle). Anyways with correctly displaying data d , if I write edit(d) then I see that R is not using UTF8 font. It displays cyrillic characters incorrectly.</p>\n<p>However, in my experiments I found out that even using incorrectly displaying data the things are working. Naturally, it is impossible to read text - that is why I have limited only to category and subcategory text columns.</p>\n<p>If possible try R under Linux or Macintosh, I have been told that unicode support / fonts are there working much easier. However, I have no personal experience with that.</p>",
      "rawMarkdown": "",
      "votes": null
    },
    {
      "id": "51015",
      "postDate": "07/21/2014 17:14:35",
      "content": "<p>Thanks for your comments. &nbsp;It has been recommended that I use Linux + R. &nbsp;But, that's not really an option for me right now. &nbsp;It is unfortunate to be held up by such a simple thing as text encoding. &nbsp;For now, &nbsp;I will just struggle through unless someone has a better option.</p>",
      "rawMarkdown": "",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 51014,
      "author_name": "sfin2015",
      "author_url": "",
      "post_date": "07/21/2014 17:00:07",
      "content": "<p>It may be related to Windows operating system (or Windows version of R). Namely, I also managed to display data correctly. However only if I limited loading of data to first few hundred records (after then comes some unicode that my R version cannot handle). Anyways with correctly displaying data d , if I write edit(d) then I see that R is not using UTF8 font. It displays cyrillic characters incorrectly.</p>\n<p>However, in my experiments I found out that even using incorrectly displaying data the things are working. Naturally, it is impossible to read text - that is why I have limited only to category and subcategory text columns.</p>\n<p>If possible try R under Linux or Macintosh, I have been told that unicode support / fonts are there working much easier. However, I have no personal experience with that.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 51015,
      "author_name": "dominic1",
      "author_url": "",
      "post_date": "07/21/2014 17:14:35",
      "content": "<p>Thanks for your comments. &nbsp;It has been recommended that I use Linux + R. &nbsp;But, that's not really an option for me right now. &nbsp;It is unfortunate to be held up by such a simple thing as text encoding. &nbsp;For now, &nbsp;I will just struggle through unless someone has a better option.</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "51008": "",
    "51014": "",
    "51015": ""
  },
  "source": "meta"
}