Bugzilla – Bug 15311
'regmatches<-' issues warning and produces incorrect results
Last modified: 2013-05-14 17:35:57 UTC
The 'regmatches<-' function issues a warning and produces incorrect results when called with a vector with length > 1 where at least one element does not match the regular expression. Specifically, this happens when the object with the match data (argument 'm') was created with 'regexpr' (it seems to work with 'gregexpr').
Steps to reproduce:
x <- c('1', 'B', '3')
m <- regexpr('\\d', x)
regmatches(x, m) <- c('A', 'C')
In `regmatches<-`(`*tmp*`, m, value = c("A", "C")) :
number of items to replace is not a multiple of replacement length
 "A" "B" "BCNA"
 "A" "B" "C"
Build date and platform:
I've seen this problem in 2.15.X versions of R, but it also seems
to be in the latest release candidate of 3.0.1:
R version 3.0.1 RC (2013-05-12 r62739) -- "Good Sport"
Platform: x86_64-unknown-linux-gnu (64-bit)
There's a simple error in the code that handled this case. I'll fix it in R-devel, and after 3.0.1 is released, port the fix to R-patched.