Replacing a string of text in a line of code with another string of text.

Sorry but I can't find the logic in your code, can you clarify what the output of the function should be or how it should looks like?. Preferably as a proper REPRoducible EXample (reprex) illustrating your issue.