This was a bug which is already fixed in R-2.0.1 patched. From the NEWS
file
o gsub(perl=TRUE) returned a string which printed with trailing
garbage if there was a match at the beginning whose
replacement was shorter. (PR#7479)
The crucial comment is that it only happened for a match at the beginning,
and sub() was using the same code.
Pre-compiled versions of R-patched for Windows XP are available on CRAN.
On Mon, 14 Feb 2005, Denham Robert wrote:
> I have a problem doing substitution using sub and perl=TRUE when the
> elements of x have fewer characters than the replacement string. Let me
> show you what I mean:
>
>> sub("m","billy","m")
> [1] "billy"
>
> But using perl=TRUE, I can only return a result as long as my x:
>> sub("m","billy","m",perl=TRUE)
> [1] "b"
>
>> sub("m","billy","ma",perl=TRUE)
> [1] "bi"
>
> Etc.
>
> Is this supposed to happen like this? I couldn't see a mention of this
> requirement in the help.
>
> I am using R 2.0.1 on windows xp.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595