After almost having finished the alternative (gsub
-based) implementation, suggested by @hwnd, I realized what was the problem with my original code. I quickly tested the fixed code and it confirmed my thoughts. I simply needed, for each subsequent replace_str
call, to re-save the result, returned by each previous call. Therefore, the fixed code looks like this:
# Now we can safely do post-processing, recovering original data
data <- replace_all(data, fixed("!@#"), ": ")
data <- replace_all(data, fixed("@@"), "::")
data <- replace_all(data, fixed("http//"), "http://")
data <- replace_all(data, fixed("mailto@"), "mailto:")
Again, thanks to @hwnd for valuable suggestions, which helped me to figure out this issue.