[BioC] Did the behavior of as.vector(Rle(some.factor)) change on purpose?

Steve Lianoglou mailinglist.honeypot at gmail.com
Tue Aug 31 20:38:46 CEST 2010


Hi,

On Tue, Aug 31, 2010 at 11:37 AM, Martin Morgan <mtmorgan at fhcrc.org> wrote:
> On 08/31/2010 07:15 AM, Steve Lianoglou wrote:
>> Hi all,
>>
>> It looks as if the as.vector call to a run length encoded factor turns
>> it to a vector of characters.
>>
>> Did this happen on accident, or was it a deliberate design decision?
>
> Bug fix
>
>> x = factor(letters)
>> as.vector(x)
>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
> "r" "s"
> [20] "t" "u" "v" "w" "x" "y" "z"
>> as.factor(x)
>  [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
>
> So
>
>> Rle(factor(letters))
> 'factor' Rle of length 26 with 26 runs
>  Lengths: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
>  Values : a b c d e f g h i j k l m n o p q r s t u v w x y z
> Levels(26): a b c d e f g h i j k l m n o p q r s t u v w x y z
>> as.vector(Rle(factor(letters)))
>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
> "r" "s"
> [20] "t" "u" "v" "w" "x" "y" "z"
>> as.factor(Rle(factor(letters)))
>  [1] a b c d e f g h i j k l m n o p q r s t u v w x y z
> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
>
> There might be edge cases where our own code has not caught up with the
> fix; please let us know...

Interesting. Although I guess it is now following the "normal R"
convention(?), this seems like it's more surprising (in this case)
then natural.

Is there some other function, then, that is something more like an
exact inverse of Rle? I guess I'd like to un-encode a vector and get
returned a vector of the type that is being encoding, w/o having to
keep track of details ... sorry, maybe I'm lazy :-)

Honestly, though, IMHO, there would be some design/use advantage to
have such a function ... and having that function named "as.vector"
... but I digress :-)

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the Bioconductor mailing list