I have a vector with two elements:
xx <- c("K[Phenylisocyanate (N-term)]SAPATGGVKKPHR", "A[Phenylisocyanate (N-term)]SAPATGGVKKPHR")
I would like to replace “[Phenylisocyanate (N-term)]” with “[Phenylisocyanate_Propionyl (Nterm)]”, but only if the part to be replaced (“[Phenylisocyanate (N-term)]”) is preceded by “K”, i.e. in the first element only
So I would like to get c(“K[Phenylisocyanate_Propionyl (Nterm)]SAPATGGVKKPHR”, “A[Phenylisocyanate (N-term)]SAPATGGVKKPHR”).
Performing this replacement with
str_replace (xx, "K[Phenylisocyanate (N-term)]", "K[Phenylisocyanate_Propionyl (Nterm)]")
results in very unexpected behaviour:
[1] “K[Phenylisocyanate_Propionyl (Nterm)]Phenylisocyanate (N-term)]SAPATGGVKKPHR”
[2] “A[Phenylisocyanate (N-term)]SAPATGGVKK[Phenylisocyanate_Propionyl (Nterm)]HR”
could you perhaps explain how I should be writing this replacement and why I get this bizzare result?