Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support data.table? #39

Open
ahookom opened this issue Feb 9, 2021 · 0 comments
Open

support data.table? #39

ahookom opened this issue Feb 9, 2021 · 0 comments

Comments

@ahookom
Copy link

ahookom commented Feb 9, 2021

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant