I have a dataframe (combined from many HTML tables) that has an address column. Some values in this column include line breaks (\r\n), but no matter what I've tried with gsub {gsub("[\r\n]", " ", tabletest)} or str_replace {(tr_replace_all(tabletest, "\r\n" , " ")} it's still returning strings with \r\n in tabletest.
The column is char values, I've tried running it with as.matrix {str_replace_all(as.matrix(tabletest), "(\r\n)" , " ")}
Df <- data.frame(TEXT = c("Here is \r\n some text with \r\n line breaks"))
Df
#> TEXT
#> 1 Here is \r\n some text with \r\n line breaks
Df$TEXT2 <- gsub("\\r\\n", "", Df$TEXT)
Df
#> TEXT
#> 1 Here is \r\n some text with \r\n line breaks
#> TEXT2
#> 1 Here is some text with line breaks
Created on 2019-12-02 by the reprex package (v0.3.0.9000)
You could also use the whitespace character class:
gsub("\\s+", " ", tabletest)
This matches one or more whitespaces in a row and replaces them with a single and normal space. If you don't want to preserve tabs, this is usually a good cleaner.