Replies: 1 comment 1 reply
|
@al-obrien, this reflects an inherent difference between the goals and philosophy of |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Prework
targetsitself, not a user error or a bug in a different package. I have done troubleshooting on my own to verify this. User questions which are not bugs intargetsshould be posted as discussions instead of bug reports.Description
Loading a data.table object from disk (e.g. serialized qs2 object), it does not automatically assign a new valid memory address. This led to a confusing bug when trying to do some in-place operations for memory efficiency.
It seems having a custom format the enforces
setDTor similar touchpoint to reset the pointer could address the issue; however, I dont know if this is the best way to implement the fix when perhaps it can be built on top of the existingqsformat (or other formats for that matter).What Im trying to get at ultimately is: what is the
targetsapproach for dealing with data.table across multiple targets while still allowing for in place operations to occur within a targets step.reprex
Memory address not valid
This will not allow in place changes to occur right away
tar_dir({ tar_script({ library(targets) library(tarchetypes) tar_option_set(format = 'qs', packages = c('data.table', 'qs2')) list( tar_target(mydt, as.data.table(iris)) ) }) tar_make() tar_load(mydt) testinplace <- function(data, val) {data[,testdata := val]} print(data.table:::selfrefok(mydt)) testinplace(mydt, 'first'); print(mydt) print(data.table:::selfrefok(data.table::setDT(mydt))) testinplace(mydt, 'second'); print(mydt) })With the helper loader
This will allow inplace to occur
tar_dir({ tar_script({ qs_dt_format <- targets::tar_format( read = function(path) { res <- qs2::qs_read(path) data.table::setDT(res) res }, write = function(object, path) { qs2::qs_save(object, path) } ) library(targets) library(tarchetypes) tar_option_set(format = 'qs', packages = c('data.table', 'qs2')) list( tar_target(mydt, as.data.table(iris), format = qs_dt_format ) ) }) tar_make() tar_load(mydt) testinplace <- function(data, val) {data[,testdata := val]} print(data.table:::selfrefok(mydt)) testinplace(mydt, 'first'); print(mydt) print(data.table:::selfrefok(data.table::setDT(mydt))) testinplace(mydt, 'second'); print(mydt) })All reactions