Hello, I'm trying to determine if a string contains asterisks using the grep function. I know that this is slightly difficult because * is a special character in regular expressions and needs to be escaped. However, escaping the * using \ doesn't work either:
if(grep("\*", model)>0) #does the model have an interaction { do something... } produces the following error message: Error in grep("*", model) : invalid regular expression '*' In addition: Warning messages: 1: '\*' is an unrecognized escape in a character string 2: unrecognized escape removed from "\*" 3: In grep("*", model) : regcomp error: 'Invalid preceding regular expression' Execution halted Any ideas anyone? Robin -- View this message in context: http://www.nabble.com/grep-for-asterisks-%22*%22%27s-tp20644195p20644195.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.