title: r - source script file that contains unicode (Farsi) character
body: <p>write the text below in a buffer and save it as a <code>.r</code> script:</p>
  
  <pre><code>letters_fa &lt;- c('الف','ب','پ','ت','ث','ج','چ','ح','خ','ر','ز','د')
  </code></pre>
  
  <p>then try these lines to <code>source()</code> it:</p>
  
  <pre><code>script &lt;- "path/to/script.R"
  file(script,
       encoding = "UTF-8") %&gt;%
    readLines() # works fine
  
  file(script,
       encoding = "UTF-8") %&gt;%
    source() # works fine
  
  source(script) # the Farsi letters in the environment are misrepresented
  
  source(script,
         encoding = "UTF-8") # gives error
  </code></pre>
  
  <p>The last line throws error. I tried to debug it and I believe there is a bug in the <code>source</code> function, in the following lines:</p>
  
  <pre><code>...
  loc &lt;- utils::localeToCharset()[1L]
  ...
  </code></pre>
  
  <p>The error occurs at <code>.Internal(parse(</code> line.</p>
  
  <pre><code>...
  exprs &lt;- if (!from_file) {
        if (length(lines)) 
          .Internal(parse(stdin(), n = -1, lines, "?", 
            srcfile, encoding))
        else expression()
      }
      else .Internal(parse(file, n = -1, NULL, "?", srcfile, 
        encoding))
  ...
  </code></pre>
  
  <p>The exact error is:</p>
  
  <pre><code>Error in source(script, encoding = "UTF-8") : 
    script.R:2:17: unexpected INCOMPLETE_STRING
  1: #' @export
  2: letters_fa &lt;- c('
                     ^
  </code></pre>