title: Converting C code into R code: parsing to change a C function in R (pow(a,b) to a^b)
body: <p>I am using Mathematica to generate equations as C code (using CForm[]), in order to export the equation as a character string and use it in R. </p>
  
  <p>For example, the CForm[] output imported into R as a character string looks like this:</p>
  
  <pre><code>"Tau * Power(Omega * (-(R * Gamma) + R),(Tau + R))"
  </code></pre>
  
  <p>My question is how best to convert the above C code into an R expression like this:</p>
  
  <pre><code>Tau * (Omega * (-(R * Gamma) + R ))^(Tau + R)
  </code></pre>
  
  <p>Following a suggestion from an earlier post about converting Mathematica code into R code <a href="https://stackoverflow.com/questions/29952792/convert-mathematica-equations-into-r-code">(Convert Mathematica equations into R code)</a>, I'm aware that a reasonable thing to do is to redefine Power() as a function, i.e.,: </p>
  
  <pre><code>Power &lt;- function(a,b) {a^b}
  </code></pre>
  
  <p>But, through a series of tests, I discovered that evaluating an expression that's in the form of:</p>
  
  <pre><code>eval(parse(text="Tau * (Omega * (-(R * Gamma) + R ))^(Tau + R)"))
  </code></pre>
  
  <p>is much faster (about 4 times fast on my mac) than the alternative of defining Power() as a function and evaluating the following:</p>
  
  <pre><code>eval(parse(text="Tau * Power(Omega * (-(R * Gamma) + R),(Tau + R))"))
  </code></pre>
  
  <p>It seems like a complex pattern matching problem, but I could not find any solutions. I appreciate any suggestions.</p>