[Rd] Argument recycling in substring()
hadley at rice.edu
Fri Jun 4 13:15:16 CEST 2010
> According to its man page substring() "expands (its) arguments
> cyclically to the length of the longest _provided_ none are of
> zero length".
> So, as expected, I get an error here:
> > substring("abcd", first=2L, last=integer(0))
> Error in substring("abcd", first = 2L, last = integer(0)) :
> invalid substring argument(s)
> But I don't get one here:
> > substring(character(0), first=1:2, last=3L)
> which is unexpected.
If you want a set of string functions that strive to be simple and
consistent you might want to look at the stringr package. And since
it's a new package, I'm very keen to remove any inconsistencies.
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
More information about the R-devel