[Rd] Argument recycling in substring()

Hadley Wickham 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)
>  character(0)
>
> 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.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-devel mailing list