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

The fsttable object needs to contain a self reference #8

Closed
MarcusKlik opened this issue Mar 25, 2018 · 1 comment
Closed

The fsttable object needs to contain a self reference #8

MarcusKlik opened this issue Mar 25, 2018 · 1 comment
Assignees
Milestone

Comments

@MarcusKlik
Copy link
Collaborator

MarcusKlik commented Mar 25, 2018

To be able to process code like:

# identify fsttable with fst file
ft <- fsttable::fst_table("1.fst")

# add simulated column 'N'
ft[, N := E * 5 + B]

In this example, column N is added as a simulated (or perhaps better: virtual?) column to the table. That means that no data is generated yet, but the new column is kept as a tree structure of known methods (* and +) and data (5).

To store that information, ft needs to be updated. To do that, a fsttable needs to update itself which requires an internal self reference (like a data.table object). Perhaps the relevant data in a fsttable can be encapsulated in a single cell list-type data.table to start with (that list element can be updated in-memory). Equivalent code:

# some object
obj <- list(Param1 = TRUE, Param2 = 1)

# store in a single cell data.table
x <- data.table::data.table(Data = list(obj))

# that creates a data.table column of type 'list'
typeof(x$Data)
#> [1] "list"

# example method for updating list element
update_obj <- function(x) {
  obj_current <- x[1, Data[[1]]]  # get obj
  obj_current[["Param3"]] <-  "value"  # update obj
  x[1, Data := list(list(obj_current))]  # rewrite to x
}

# update in-place
update_obj(x)

# the element in x now points to the updated obj
x$Data[[1]]
#>    Param1 Param2 Param3
#> 1:   TRUE      1  value
@MarcusKlik MarcusKlik self-assigned this Mar 25, 2018
@MarcusKlik MarcusKlik added this to the `data.table` interface milestone Mar 25, 2018
@MarcusKlik
Copy link
Collaborator Author

The remote proxy object is now kept inside a data.table cell, as is a remote proxy state object. Both can be updated in-memory.

Closing for now, when we want to update the auto-completion of columns after an in-place modification (with :=), a self-reference is still needed. But for a generated new datatableproxy object, that's not necessary.

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

No branches or pull requests

1 participant