You need to strip \r
and \n
to remove carriage returns and new lines.
x <- "foo\nbar\rbaz\r\nquux"
gsub("[\r\n]", "", x)
## [1] "foobarbazquux"
Or
library(stringr)
str_replace_all(x, "[\r\n]" , "")
## [1] "foobarbazquux"
More Related Contents:
- grep using a character vector with multiple patterns
- Selecting data frame rows based on partial string match in a column
- Matching multiple patterns
- How to use grep()/gsub() to find exact match
- How to remove all whitespace from a string?
- Using regex in R to find strings as whole words (but not strings as part of words)
- Replace multiple letters with accents with gsub
- Replace specific characters within strings
- Remove parentheses and text within from strings in R
- Replace / translate characters in a string
- Remove part of a string
- regular expressions in base R: ‘perl=TRUE’ vs. the default (PCRE vs. TRE)
- Finding the indexes of multiple/overlapping matching substrings
- Extracting unique numbers from string in R
- Remove everything after space in string
- gsub() in R is not replacing ‘.’ (dot)
- Use grepl to search either of multiple substrings in a text [duplicate]
- R grep: is there an AND operator?
- Line break in expression()?
- Remove all punctuation except apostrophes in R
- grepl for a period “.” in R?
- select columns based on multiple strings with dplyr contains()
- How to delete everything after nth delimiter in R?
- Check if string contains ONLY NUMBERS or ONLY CHARACTERS (R)
- pivot_longer into multiple columns
- Remove part of a string in dataframe column (R)
- “‘\w’ is an unrecognized escape” in grep
- How to strsplit using ‘|’ character, it behaves unexpectedly?
- How to grep a word exactly
- remove text after final period in string