[Rd] Argument recycling in substring()

From: Hervé Pagès <hpages_at_fhcrc.org>
Date: Thu, 03 Jun 2010 17:53:33 -0700


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.

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

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


Hervé Pagès

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

E-mail: hpages_at_fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

R-devel_at_r-project.org mailing list
Received on Fri 04 Jun 2010 - 01:02:07 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 Jun 2010 - 15:16:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive