From hadley at rice.edu  Fri Jun  4 13:15:16 2010
From: hadley at rice.edu (Hadley Wickham)
Date: Fri, 4 Jun 2010 06:15:16 -0500
Subject: [Rd] Argument recycling in substring()
In-Reply-To: <4C084E8D.4000002@fhcrc.org>
References: <4C084E8D.4000002@fhcrc.org>
Message-ID: <AANLkTimC2CL6cEZHdIUBjQY7b5Q3eXztoev0mM7QuF-d@mail.gmail.com>

> 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/



[Rd] Argument recycling in substring()
Hadley Wickham