Skip to content

[Bioc-devel] names, mcols and metadata are not changed in "[<-" operator of class Vector

2 messages · Hervé Pagès, Sebastian Gibb

#
Hi Sebastian,

This is the expected behavior and it's motivated by how [<- behaves on
ordinary vectors:

   x <- setNames(1:3, LETTERS[1:3])

Then:

   > x
   A B C
   1 2 3

Replacing the first two elements:

   x[2:1] <- x[1:2]

Then:

   > x
   A B C
   2 1 3

The names are preserved.

So we need to think of [<- as an operator that touches the values of
a vector-like object without touching its structure or its attributes.
People sometimes rely on this behavior to stuff the entire object with
a given value:

   x[] <- some_value

They wouldn't expect this to destroy the names or metadata cols that
are on 'x'.

Hope that makes sense,

Cheers,
H.
On 05/07/2014 11:59 AM, Sebastian Gibb wrote:

  
    
#
Hi Herv?,

thanks for the explanation. I never recognized that this happens with ordinary
vectors, too.

Of course, I see that it would be a bad style to overload "[<-" for my own
class to behave like I want to.

So I need to update the metadata manually.

Kind regards,

Sebastian
On 2014-05-07 20:18:58, hpages at fhcrc.org wrote: