title: write.csv() writes a different result from Mac OS than from Windows 10?
body: <p>Character strings that look completely normal when printed to the RStudio console but appear as strange characters when written to csv and opened with excel. </p>
  
  <h3>Reproducible example</h3>
  
  <p>The following generates the object that appears as the string <code>"a wit"</code>, then writes it to a csv:</p>
  
  <pre><code># install.packages("dplyr")
  library(dplyr)
  
  serialized_char &lt;- "580a000000030003060200030500000000055554462d380000001000000001000080090000000661c2a0776974"
  
  (string &lt;- serialized_char %&gt;% 
      {substring(., seq(1, nchar(.), 2), seq(2, nchar(.), 2))} %&gt;% 
      paste0("0x", .) %&gt;% 
      as.integer %&gt;% 
      as.raw %&gt;% 
      unserialize())
  [1] "a wit"
  
  write.csv(string, "myfile.csv", row.names=F)
  </code></pre>
  
  <p>This is what it looks like when written from <strong>Mojave</strong> (and viewed in excel in OSX Mojave) - <strong>contains undesirable characters</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/GlX7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GlX7x.png" alt="enter image description here"></a></p>
  
  <p>This is when it's written in <strong>High Sierra</strong> (and viewed in excel in High Sierra) - <strong>contains undesirable characters</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/jwAUZm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jwAUZm.png" alt="enter image description here"></a></p>
  
  <p>When is when written from <strong>Windows 10</strong> and viewed in excel on windows 10 (looks good!):</p>
  
  <p><a href="https://i.stack.imgur.com/Sp75d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Sp75d.png" alt="enter image description here"></a></p>
  
  <p>This is when it is written from <strong>Mojave</strong>, but viewed in excel on Windows 10 - - <strong>still contains undesirable characters</strong>: </p>
  
  <p><a href="https://i.stack.imgur.com/zFfeW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zFfeW.png" alt="enter image description here"></a></p>
  
  <h3>Question</h3>
  
  <p>I have a lot of character data of the form above (with characters that looks strange when written to csv and opened in excel) - how can these be cleaned in such a way that the text appears 'normally' in excel. </p>
  
  <h3>What I've tried</h3>
  
  <p>I have tried 4 things so far</p>
  
  <pre><code>write.csv(string, "myfile.csv", fileEncoding = 'UTF-8')
  
  Encoding(string) &lt;- "latin-1"
  
  Encoding(string) &lt;- "UTF-8"
  
  iconv(string, "UTF-8", "latin1", sub=NA)
  
  </code></pre>