[R] grep for asterisks "*"'s

Robin Clark robalexclark at hotmail.com
Sun Nov 23 09:41:02 CET 2008


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.



More information about the R-help mailing list