regex - Insertion of characters in strings in R -
i insert " & " between letters (upper-case , lower-case), not before or after letters, , replace each lower-case letter x tt$x==0 , each upper-case letter x tt$x==1 , , each + )|( , plus opening bracket , closing bracket around entire string, expression can evaluated in r. example, have string st <- "abc + de + fghij" the result should this: "(tt$a==1 & tt$b==0 & tt$c==1) | (tt$d==0 & tt$e==0) | (tt$f==1 & tt$g==1 & tt$h==1 & tt$i==1 & tt$j==1)" could gsub() function? a bunch of regexps elegant, , hard debug. above regexp solution fails if there's not exact spacing between elements. > tt("abc+b") [1] "(tt$a==0 & tt$b==1 & tt$c==0+tt$b==0)" > tt("abc + b") [1] "(tt$a==0 & tt$b==1 & tt$c==0) | (tt$b==0)" sometimes have split bits , process them. here's solution: dochar = vectorize( function(c){ sprintf("tt$%...