Magic data.table that resists subset

My colleague sent the following data.table

(version 1.9.4 from CRAN):

w <- structure(
  list(
    type = c("current", "prior"),
    value = c(10, 20)
    ), 
  class = c("data.table", "data.frame"), 
  index = structure(integer(0), type = c(2L, 1L))
  )

      

At first, the w brush looks like a regular one data.table

:

> w
      type value
1: current    10
2:   prior    20
> w[type=='prior',]
    type value
1: prior    20

      

But for some reason it cannot be a subset of type == 'current'

:

> w[type=='current',]
Empty data.table (0 rows) of 2 cols: type,value

      

Using the function get

solves this problem:

> w[get('type')=='current',]
      type value
1: current    10

      

Like removing the index from data.table:

x <- structure(
  list(
    type = c("current", "prior"),
    value = c(10, 20)
  ), 
  class = c("data.table", "data.frame")
)
> x
      type value
1: current    10
2:   prior    20

      

What is this "index" attribute on the data.table and how can I prevent it from being created in the future? I know that my colleague did not intentionally create this index, but somehow during a union or subset operation this data.table acquired a magic property.

+3


source to share





All Articles