title: Modify R Console input/output encoding in Eclipse + StatET
body: <p>I'm trying to make Eclipse's console work with Polish (or any other non-english) characters, whether ANSI or UTF-8 encoded. It seems that, on Windows, R is only able to encode with ANSI, while Eclipse"s console forces UTF-8 or ISO-8859-1.</p>
  
  <p>Trying to use ANSI CP-1250 (default Polish encoding for Windows), I: </p>
  
  <ul>
  <li>encode the R script-file as ANSI CP-1250</li>
  <li>set Eclipse properties, including "R Script File" content type (in General -> Content Types -> Text), "Text file encoding" (in General -> Workspace), Console encoding (in "Run Configurations" -> "R Console" -> "Common", as cp1250</li>
  <li>set JVM properties in eclipse.ini, by adding lines: "-Dclient.encoding.override=cp1250", "-Dfile.encoding=cp1250"</li>
  </ul>
  
  <p>with no effect at all. <strong>How may I force Eclipse to encode and display in R's locale?</strong></p>
  
  <p>The exactly same behavior persists, when all these options are set to 'UTF-8', instead of 'CP-1250'. Please note I'm unable to set R's locale to 'UTF-8' on Windows. Worth to mention that Rstudio, Rgui and Rterm do not pose any problems with default CP-1250 encoding, strings are displayed correctly.</p>
  
  <p><strong>Executed script:</strong></p>
  
  <pre><code>print(Sys.getlocale())
  Sys.setenv(LANG = 'pl_PL.cp1250')
  
  x &lt;- 'ąęłóżść'
  message('Printing variable'); print(x); print(charToRaw(x))
  </code></pre>
  
  <p><strong>Output 1:</strong> 'Run via source'--> string encoded with ANSI CP1250, but printed as ISO-8859-1</p>
  
  <pre><code>&gt; source("C:/mjktfw/pit/workspace/test_encoding/run3.R", echo=FALSE, encoding="cp1250")
  [1] "LC_COLLATE=Polish_Poland.1250;LC_CTYPE=Polish_Poland.1250;LC_MONETARY=Polish_Poland.1250;LC_NUMERIC=C;LC_TIME=Polish_Poland.1250"
  Printing variable
  [1] "¹ê³ó
  [1] b9 ea b3 f3 bf 9c e6
  </code></pre>
  
  <p><strong>Output 2:</strong> 'Run via submitting directly'--> string encoded with UTF-8, printed correctly</p>
  
  <pre><code>&gt; print(Sys.getlocale())
  [1] "LC_COLLATE=Polish_Poland.1250;LC_CTYPE=Polish_Poland.1250;LC_MONETARY=Polish_Poland.1250;LC_NUMERIC=C;LC_TIME=Polish_Poland.1250"
  &gt; Sys.setenv(LANG = 'pl_PL.cp1250')
  &gt; 
  &gt; x &lt;- 'ąęłóżść'
  &gt; message('Printing variable'); print(x); print(charToRaw(x))
  Printing variable
  [1] "ąęłóżść"
   [1] c4 85 c4 99 c5 82 c3 b3 c5 bc c5 9b c4 87
  </code></pre>
  
  <p><strong>Output 3:</strong> copy-paste to console: --> string encoded with UTF-8, printed correctly</p>
  
  <pre><code>&gt; print(Sys.getlocale())
  [1] "LC_COLLATE=Polish_Poland.1250;LC_CTYPE=Polish_Poland.1250;LC_MONETARY=Polish_Poland.1250;LC_NUMERIC=C;LC_TIME=Polish_Poland.1250"
  &gt; Sys.setenv(LANG = 'pl_PL.cp1250')
  &gt; 
  &gt; x &lt;- 'ąęłóżść'
  &gt; message('Printing variable'); print(x); print(charToRaw(x))
  Printing variable
  [1] "ąęłóżść"
   [1] c4 85 c4 99 c5 82 c3 b3 c5 bc c5 9b c4 87
  </code></pre>
  
  <p><strong>Output 4:</strong> 'Run entire command in R' shortcut --> string encoded as ANSI CP1250, but printed as plaintext Unicode codepoints</p>
  
  <pre><code>&gt; print(Sys.getlocale())
  [1] "LC_COLLATE=Polish_Poland.1250;LC_CTYPE=Polish_Poland.1250;LC_MONETARY=Polish_Poland.1250;LC_NUMERIC=C;LC_TIME=Polish_Poland.1250"
  &gt; Sys.setenv(LANG = 'pl_PL.cp1250')
  &gt; x &lt;- 'ąęłóżść'
  &gt; message('Printing variable')
  Printing variable
  &gt; print(x)
  [1] "&lt;U+00B9&gt;&lt;ea&gt;&lt;U+00B3&gt;&lt;f3&gt;&lt;U+00BF&gt;&lt;U+009C&gt;&lt;e6&gt;"
  &gt; print(charToRaw(x))
  [1] b9 ea b3 f3 bf 9c e6
  </code></pre>
  
  <hr>
  
  <h2>Edit</h2>
  
  <p>After some more tinkering it occurs, that above cases result from different 'raw' encoding and <code>Encoding()&lt;-</code> parameters of the string. The output below compares R/Rstudio and Eclipse/StatET behavior:</p>
  
  <p><strong>Eclipse</strong></p>
  
  <pre><code>&gt; # UTF-8 encoded string
  &gt; char &lt;- rawToChar(as.raw(c(0xea, 0xb3, 0x9c)))
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: 곜"
  [1] "Encoding: unknown | Raw: ea b3 9c"
  &gt; 
  &gt; Encoding(char) &lt;- 'UTF-8'
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: &lt;U+ACDC&gt;"
  [1] "Encoding: UTF-8 | Raw: ea b3 9c"
  &gt; 
  &gt; # ANSI encoded string
  &gt; char &lt;- rawToChar(as.raw(c(0xc4, 0x99, 0xc5, 0x82, 0xc5, 0x9b)))
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: ęłś"
  [1] "Encoding: unknown | Raw: c4 99 c5 82 c5 9b"
  &gt; 
  &gt; Encoding(char) &lt;- 'UTF-8'
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: 곜"
  [1] "Encoding: UTF-8 | Raw: c4 99 c5 82 c5 9b"
  </code></pre>
  
  <p><strong>Rstudio</strong></p>
  
  <pre><code>&gt; # UTF-8 encoded string
  &gt; char &lt;- rawToChar(as.raw(c(0xea, 0xb3, 0x9c)))
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: ęłś"
  [1] "Encoding: unknown | Raw: ea b3 9c"
  &gt; 
  &gt; Encoding(char) &lt;- 'UTF-8'
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: 곜"
  [1] "Encoding: UTF-8 | Raw: ea b3 9c"
  &gt; 
  &gt; # ANSI encoded string
  &gt; char &lt;- rawToChar(as.raw(c(0xc4, 0x99, 0xc5, 0x82, 0xc5, 0x9b)))
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: Ä™Ĺ‚Ĺ›"
  [1] "Encoding: unknown | Raw: c4 99 c5 82 c5 9b"
  &gt; 
  &gt; Encoding(char) &lt;- 'UTF-8'
  &gt; sprintf('String: %s', char); sprintf('Encoding: %s | Raw: %s', Encoding(char), paste(charToRaw(char), collapse = ' '))
  [1] "String: ęłś"
  [1] "Encoding: UTF-8 | Raw: c4 99 c5 82 c5 9b"
  </code></pre>