Skip to content

support data.table? #39

Description

@ahookom

Hey, thanks for making this!

I have an existing code base oriented around data.table, and I'd love to get the memory savings from using these instead of numeric. I'm wondering: would it be possible to add support for inserting vectors of these floats into a data.table as a column? It seems the class would probably have to inherit from an atomic such as vector or list to make that work.

Here's the very basic thing I have tried in R-3.3.1 with float==0.2-2 and data.table==1.9.6:

> library(float)
> library(data.table)

> ex <- fl(c(3.2, 1e7, -2.8e-4))
> dt <- data.table(foo=c('bar', 'baz', 'bar'))
> dt
   foo
1: bar
2: baz
3: bar
> dt[,float:=ex]
Error in X[[i]] : this S4 class is not subsettable

borrowing from your bracket.R:

> double_bracket_float32 = function(x, i, exact=TRUE)
{
  d = x@Data[[i, exact=exact]]
  float32(d)
}
> setMethod("[[", signature(x="float32"), double_bracket_float32)

but now:

> dt[,foo:=ex]
Error in `[.data.table`(dt, , `:=`(foo, ex)) :
  RHS of assignment is not NULL, not an an atomic vector (see ?is.atomic) and not a list column.

since data.table is running is.atomic, I think the class definition would have to inherit from an atomic to get past this.

Perhaps I could wrap your class with my own that inherits from vector or list in order to achieve my goal?

Please let me know your thoughts. Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions