On Wed, 23 Mar 2005 [EMAIL PROTECTED] wrote:
1) In your cases, the integer 'x' argument is auto-coerced to character, however that fails as soon as 'perl = TRUE' is used.
> sub('^','v_', 1:3, perl=TRUE) Error in sub.perl(pattern, replacement, x, ignore.case) : invalid argument
{one can argue that this is not a bug, since the help file asks for 'x' to be a character vector; OTOH, we have as.character(.) magic in many other places, i.e. quite naturally here; at least perl=TRUE and perl=FALSE should behave consistently.}
I believe the bug is in the PERL=FALSE case. This coercion is undocumented, and e.g.
grep('^1', 1:3, perl=TRUE)
Error in grep.perl(pattern, x, ignore.case, value, useBytes) : invalid argument
grep('^1', 1:3, perl=FALSE)
Error in grep(pattern, x, ignore.case, extended, value, fixed, useBytes) : invalid argument
do not accept non-character arguments. The only one that does AFAICS is [g]sub(perl=FALSE), and the other functions like tolower, substr, strsplit, chartr, agrep do not.
The consistent thing to do seems to be to remove the anomalous coercion. Otherwise we need to at least change grep and regexpr.
-- Brian D. Ripley, [EMAIL PROTECTED] 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
______________________________________________ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel