From maechler at stat.math.ethz.ch  Fri Jun  4 11:46:29 2010
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Fri, 4 Jun 2010 11:46:29 +0200
Subject: [Rd] Argument recycling in substring()
In-Reply-To: <4C084E8D.4000002@fhcrc.org>
References: <4C084E8D.4000002@fhcrc.org>
Message-ID: <19464.52085.361753.726627@lynne.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?


    HP> Otherwise, yes substring() will recycle its arguments to the
    HP> length of the longest:

    >> substring("abcd", first=1:3, last=4:3)
    HP> [1] "abcd" "bc"   "cd"




    HP> Cheers,
    HP> H.

    HP> -- 
    HP> Herv? Pag?s

    HP> Program in Computational Biology
    HP> Division of Public Health Sciences
    HP> Fred Hutchinson Cancer Research Center
    HP> 1100 Fairview Ave. N, M2-B876
    HP> P.O. Box 19024
    HP> Seattle, WA 98109-1024

    HP> E-mail: hpages at fhcrc.org
    HP> Phone:  (206) 667-5791
    HP> Fax:    (206) 667-1319

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



[Rd] Argument recycling in substring()
Martin Maechler