[Rd] substring() and propagation of names

Hervé Pagès hpages at fhcrc.org
Sat Jan 4 02:02:31 CET 2014


On 12/13/2013 01:07 AM, Hervé Pagès wrote:
> Hi,
>
> In R < 3.0.0, we used to get:
>
>    > substring(c(A="abcdefghij", B="123456789"), 2, 6:2)
>          A       B       A       B       A
>    "bcdef"  "2345"   "bcd"    "23"     "b"
>
> But in R >= 3.0.0, we get:
>
>    > substring(c(A="abcdefghij", B="123456789"), 2, 6:2)
>    [1] "bcdef" "2345"  "bcd"   "23"    "b"
>
> The names are not propagated anymore.

Looks like a regression introduced at commit 59891 where many functions
were modified to use rep_len() instead of rep() internally. Problem is,
unlike rep(), rep_len() does not propagate the names. Given the number
of files that were touched by this commit, a lot of functions could be
affected. For example complex():

   In R < 3.0.0:

     > complex(modulus=c(a=-1, b=0.77))
            a        b
     -1.00+0i  0.77+0i

   But in R >= 3.0.0:

     > complex(modulus=c(a=-1, b=0.77))
     [1] -1.00+0i  0.77+0i

etc...

Cheers,
H.

>
> Is this an intended change or a bug? I can't find anything about
> this in the NEWS file. The man page for substring() in R >= 3.0.0
> still states:
>
>    Value:
>
>       ...
>
>       For ‘substring’, a character vector of length the longest of the
>       arguments.  This will have names taken from ‘x’ (if it has any
>       after coercion, repeated as needed), and other attributes copied
>       from ‘x’ if it is the longest of the arguments).
>
> Also note that the first argument of substring() is 'text' not 'x'.
>
> Thanks,
> H.
>

-- 
Hervé Pagès

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

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



More information about the R-devel mailing list