title: how to both reorder and substitute parts of a string in r?
body: <p>I am trying to translate some textual information into R scripts. For that I need to substitute and reorder parts of the strings.</p>
  
  <pre><code>example &lt;- "varA is 1 and not varB is 1"
  </code></pre>
  
  <p>This is what I want as a result (a part of an R script):</p>
  
  <pre><code>exampleTrans &lt;- "varA == 1 &amp; varB != 1"
  </code></pre>
  
  <p>This is what I can do now:</p>
  
  <pre><code>exampleTrans &lt;- gsub(" is "," == ", example)
  exampleTrans &lt;- gsub(" and ", " &amp; ", exampleTrans)
  print(exampleTrans)
  [1] "varA == 1 &amp; not varB == 1"
  </code></pre>
  
  <p>The first part of the string is exactly what I wanted, so now I only need to change somthing in the second part. "not varB == 1" needs to be changed into "varB != 1".</p>
  
  <p>Does anyone have an idea about how to do that? Is it even possible? Many thanks in advance!</p>