rm_(...)
rm_default
.
Generally, pattern
and extract
are the most useful parameters
to change. Arguments that can be set include:
TRUE
removes leading and trailing white
spaces.TRUE
extra white spaces and escaped
character will be removed.fixed = TRUE
) to be matched in the given
character vector.pattern
.TRUE
strings are extracted into a list of
vectors.pattern
begins with "@rm_"
.gsub
.rm_XXX
functions but with user defined defaults.
Remove/replace/extract substrings from a string. A function generator used
to make regex functions that operate typical of other qdapRegex
rm_XXX
functions.
rm_digit <- rm_(pattern="[0-9]") rm_digit(" I 12 li34ke ice56cream78. ")[1] "I like icecream."rm_lead <- rm_(pattern="^\\s+", trim = FALSE, clean = FALSE) rm_lead(" I 12 li34ke ice56cream78. ")[1] "I 12 li34ke ice56cream78. "rm_all_except_letters <- rm_(pattern="[^ a-zA-Z]") rm_all_except_letters(" I 12 li34ke ice56cream78. ")[1] "I like icecream"extract_consec_num <- rm_(pattern="[0-9]+", extract = TRUE) extract_consec_num(" I 12 li34ke ice56cream78. ")[[1]] [1] "12" "34" "56" "78"## Using the supplemental dictionary dataset: x <- "A man lives there! The dog likes it. I want the map. I want an apple." extract_word_after_the <- rm_(extract=TRUE, pattern="@after_the") extract_word_after_a <- rm_(extract=TRUE, pattern="@after_a") extract_word_after_the(x)[[1]] [1] "dog" "map"extract_word_after_a(x)[[1]] [1] "man" "apple"f <- rm_(pattern="@time_12_hours") f("I will go at 12:35 pm")[1] "I will go at"x <- c( "test@aol.fg.com", "test@hotmail.com", "test@xyzrr.lk.edu", "test@abc.xx.zz.vv.net" ) file_ext2 <- rm_(pattern="(?<=\\.)[a-z]*$", extract=TRUE) tools::file_ext(x)[1] "com" "com" "edu" "net"file_ext2(x)[[1]] [1] "com" [[2]] [1] "com" [[3]] [1] "edu" [[4]] [1] "net"
rm_default