title: UTF-8 / Unicode Text Encoding with RPostgreSQL
body: <p>I'm running R on a Windows machine which is directly linked to a PostgreSQL database. I'm not using RODBC. My database is encoded in UTF-8 as confirmed by the following R command:</p>
  
  <pre><code>dbGetQuery(con, "SHOW CLIENT_ENCODING")
  #   client_encoding
  # 1            UTF8
  </code></pre>
  
  <p>However, when some text is read into R, it displays as strange text in R.  </p>
  
  <p>For example, the following text is shown in my PostgreSQL database:
  "Stéphane"</p>
  
  <p>After exporting to R it's shown as:
  "StÃ©phane"
  (the <strong>é</strong> is encoded as <strong>Ã©</strong>)  </p>
  
  <p>When importing to R I use the <code>dbConnect</code> command to establish a connection and the <code>dbGetQuery</code> command to query data using SQL.  I do not specify any text encoding anywhere when connecting to the database or when running a query.</p>
  
  <p>I've searched online and can't find a direct resolution to my issue.  I found <a href="https://stackoverflow.com/questions/7167298/rodbc-character-encoding-error-with-postgresql">this link</a>, but their issue is with RODBC, which I'm not using.</p>
  
  <p><a href="http://www.i18nqa.com/debug/utf8-debug.html" rel="noreferrer">This link</a> is helpful in identifying the symbols, but I don't just want to do a find &amp; replace in R... way too much data.</p>
  
  <p>I did try running the following commands below and I arrived at a warning.</p>
  
  <pre><code>Sys.setlocale("LC_ALL", "en_US.UTF-8")
  # [1] ""
  # Warning message:
  # In Sys.setlocale("LC_ALL", "en_US.UTF-8") :
  #   OS reports request to set locale to "en_US.UTF-8" cannot be honored
  Sys.setenv(LANG="en_US.UTF-8")
  Sys.setenv(LC_CTYPE="UTF-8")
  </code></pre>
  
  <p>The warning occurs on the <code>Sys.setlocale("LC_ALL", "en_US.UTF-8")</code> command.  My intuition is that this is a Windows specific issue and doesn't occur with Mac/Linux/Unix.</p>