tl; dr: agrep(..., fixed=F) doesn't seem to work with '|' the character. Use aregexec .
In further research, I think this is a mistake, and that agrep(..., fixed=F) does not work with '|' regexes (although adist(..., fixed=F) does).
To clarify, please note that
adist('(asdf|fdsa)', 'asdf', fixed=T) # 7 nchar('(asdf|fdsa)') # 11
If 'asdf' were agrep 'd for the line of irregular expression' (asdf | fdsa) ', then it would have a distance of 7.
In this note:
agrep('(asdf|fdsa)', 'asdf', fixed=F, max.distance=7) # 1 agrep('(asdf|fdsa)', 'asdf', fixed=F, max.distance=6) # integer(0)
These are the results that I expect if fixed=T If fixed=F , my regular expression will exactly match "asdf" and the distance will be 0, so I always get the result "1" from agrep .
So it looks agrep(pattern, x, fixed=F) doesn't work , i.e. actually considers fixed as TRUE for this type of template.
As @Arun mentions, it could just be '|' regular expressions that don't work. For example, agrep('la[sb]y', 'lazy', fixed=FALSE) works as expected.
EDIT: Workaround (thanks @Arun)
The aregexec function seems to work.
> aregexec('(asdf|fdsa)', 'asdf', fixed=F) [[1]] [1] 1 1 attr(,"match.length") [1] 4 4