From pdalgd at gmail.com  Fri Jun  4 13:06:47 2010
From: pdalgd at gmail.com (peter dalgaard)
Date: Fri, 4 Jun 2010 13:06:47 +0200
Subject: [Rd] Argument recycling in substring()
In-Reply-To: <AANLkTim3FDCsrgi3rMJ2WeQy_BbiWRDyLXFgjQFc3z7f@mail.gmail.com>
References: <4C084E8D.4000002@fhcrc.org>
	<19464.52085.361753.726627@lynne.math.ethz.ch>
	<AANLkTim3FDCsrgi3rMJ2WeQy_BbiWRDyLXFgjQFc3z7f@mail.gmail.com>
Message-ID: <2227612C-77EA-4223-BC6D-9CE7EA926E27@gmail.com>


On Jun 4, 2010, at 12:10 PM, Deepayan Sarkar wrote:

> 2010/6/4 Martin Maechler <maechler at stat.math.ethz.ch>:
>>>>>>> "HP" == Herv? Pag?s <hpages at fhcrc.org>
>>>>>>>     on Thu, 03 Jun 2010 17:53:33 -0700 writes:
>> 
>>    HP> Hi,
>>    HP> According to its man page substring() "expands (its) arguments
>>    HP> cyclically to the length of the longest _provided_ none are of
>>    HP> zero length".
>> 
>>    HP> So, as expected, I get an error here:
>> 
>>    >> substring("abcd", first=2L, last=integer(0))
>>    HP> Error in substring("abcd", first = 2L, last = integer(0)) :
>>    HP> invalid substring argument(s)
>> 
>>    HP> But I don't get one here:
>> 
>>    >> substring(character(0), first=1:2, last=3L)
>>    HP> character(0)
>> 
>>    HP> which is unexpected.
>> according to the docu.
>> 
>> My gut feeling would say that the documentation should be
>> updated in this case, rather than the implementation.
>> 
>> RFC! other opinions?
> 
> I agree. The current behaviour is reasonable.

Yes, but I don't see how it is inconsistent with the docs. It says that it won't recycle, and it doesn't. The fact that the combination of 0-length index and a positive-length x is nonsensical is an orthogonal issue. (Notice, BTW, that
x <- character(0); i <- integer(0); substr(x,i,i) does NOT give an error.)

Of course it is never harmful to be explicit about things....

> 
> -Deepayan
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Argument recycling in substring()
peter dalgaard