title: Rpy2 parsing error while opening external code
body: <p>I'm having problems in running external R script from python using rpy2 library. The setting is the same of <a href="https://stackoverflow.com/questions/39953624/rpy2-running-r-function">this question</a> but I don't feel it solved my issue. By summarizing the problem, I'm able to run an R function by hard typing it but not but calling the script that contains it since I get a parsing error.</p>
  <p>More specifically, I have an R script called 'produce_CI.r' which contains the following code</p>
  <pre><code>library(readr)
  library(bnlearn)
  
  perform_CI &lt;- function(c1, c2, s, dataset, test_type){
    print(c(c1,c2,s))
    if (!s[1]==&quot;()&quot;){
      t &lt;- ci.test(c1, c2, c(s), data = dataset, test = test_type)
    }else{
      t &lt;- ci.test(c1, c2, data = dataset, test = test_type, debug = TRUE)
    }
    print(t)
    return &lt;- t
  }
  </code></pre>
  <p>and I try to call it from python using this code</p>
  <pre><code>import rpy2.robjects as robjects
  import os
  
  robjects.r(&quot;&quot;&quot;source(%s)&quot;&quot;&quot; % os.path.join(os.getcwd(), 'produce_CI.r'))
  </code></pre>
  <p>which gives me the following parsing error</p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;path/ci_venv/lib/python3.8/site-packages/rpy2/robjects/__init__.py&quot;, line 437, in __call__
      p = rinterface.parse(string)
    File &quot;path/ci_venv/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py&quot;, line 45, in _
      cdata = function(*args, **kwargs)
    File &quot;path/ci_venv/lib/python3.8/site-packages/rpy2/rinterface.py&quot;, line 103, in parse
      res = _rinterface._parse(robj.__sexp__._cdata, num, rmemory)
    File &quot;path/ci_venv/lib/python3.8/site-packages/rpy2/rinterface_lib/_rinterface_capi.py&quot;, line 652, in _parse
      raise RParsingError('Parsing status not OK',
  rpy2.rinterface_lib._rinterface_capi.RParsingError: Parsing status not OK - PARSING_STATUS.PARSE_ERROR
  </code></pre>
  <p>The only way I'm able to make the code run is by hard-coding it using a string in python</p>
  <pre><code>from rpy2.robjects.packages import SignatureTranslatedAnonymousPackage as STAP
  
  r_code = '''library(readr)
  library(bnlearn)
  
  perform_CI &lt;- function(c1, c2, s, dataset, test_type){
    print(c(c1,c2,s))
    if (!s[1]==&quot;()&quot;){
      t &lt;- ci.test(c1, c2, c(s), data = dataset, test = test_type)
    }else{
      t &lt;- ci.test(c1, c2, data = dataset, test = test_type, debug = TRUE)
    }
    print(t)
    return &lt;- t
  }
  '''
  
  testy = STAP(r_code, &quot;testy&quot;)
  # ====
  # removed code to initialize t,x,z_vec, df_r and r_method
  # ====
  testy.perform_CI(t,x,z_vec, df_r, r_method)
  </code></pre>
  <p><strong>I'm not satisfied by this solution since I'd like to call directly the code in the R script since then I don't have duplicate code.</strong> I'm therefore searching for a solution to this parsing error, not a way to just &quot;make the code work&quot;.</p>
  <p>I feel like an issue may be that I'm writing the code on MacOS and running it on an Ubuntu machine therefore there may be problems with line endings. Therefore I tried to read the R code with python as it was a string and (obviously) I see lot a '\n' everytime there's a new line.</p>
  <p>I'm running this code with python 3.8 and rpy2 version 3.4.5</p>