To remove all special characters from a string, you can use the string_replace_all function from the stringr package as follows:
To remove all the punctuation characters:
x <- "a1~!@#$%^&*(){}_+:\"<>?,./;'[]-="
str_replace_all(x, "[[:punct:]]", " ")
[1] "a1~ $ ^ + <> ="
To remove all the non-alphanumeric characters:
str_replace_all(x, "[^[:alnum:]]", " ")
[1] "a1
You can also use the gsub function from the base package as follows:
gsub("[^[:alnum:]]", " ", x)
[1] "a1