title: R: workaround for variable-width lookbehind
body: <p>Given this vector:</p>
  
  <pre><code>ba &lt;- c('baa','aba','abba','abbba','aaba','aabba')'
  </code></pre>
  
  <p>I want to change the final <code>a</code> of each word to <code>i</code> except <code>baa</code> and <code>aba</code>. </p>
  
  <p>I wrote the following line ...</p>
  
  <pre><code>gsub('(?&lt;=a[ab]b{1,2})a','i',ba,perl=T)
  </code></pre>
  
  <p>but was told: <em>PCRE pattern compilation error 'lookbehind assertion is not fixed length' at ')a'</em>. </p>
  
  <p>I looked around a little bit and apparently R/Perl can only lookahead for a variable width, not lookbehind. Any workaround to this problem? Thanks!</p>