1

I am having problems to call methods of ReferenceClass objects and assign the return values directly by reference to a data.table column (data.table version 1.9.3, R version 3.1) as this minimal example shows:

RF <- setRefClass(
  Class = "RF",
  methods = list(
    get = function() { "/foo/bar" }
  )
)
rf <- RF$new()

mdt <- data.table( x= c("a", "b"), y = 1:2 )
mdt[ , z := rf$get() ] # gives warning

> mdt$z
[[1]]
`$`

[[2]]
rf

mdt[ , rf$get() ] works as expected, while mdt[ , list( z = rf$get()) ][ , z] gives a weird result as well and mdt[ , unlist(list( z = rf$get())) ] gives an error.

I do not need a solution like evaluate rf$get() outside mdt and then assign the result. I'd rather like to understand what is going on here, since I am making vast use of data.tables and ReferenceClasses and would like to use them properly together.

Beasterfield
  • 7,023
  • 2
  • 38
  • 47
  • this has nothing to do with `ReferenceClass` and is a bug in `construct`/`deconstruct_and_eval` internal functions - please submit a bug report - any construct of form `dt[, a := b$c()]` will fail – eddi Aug 19 '14 at 14:53
  • @eddi so if I got this right the new home of `data.table` and accordingly tracking the bugs is github and not r-forge any longer? – Beasterfield Aug 19 '14 at 14:56

1 Answers1

2

Thanks for filing the issue. This has been now fixed in 1.9.5. From NEWS:

j-expressions in DT[, col := x$y()] (or) DT[, col := x[[1]]()] are now (re)constructed properly. Thanks to @ihaddad-md for reporting. Closes #774.

Your code gives the result:

#    x y        z
# 1: a 1 /foo/bar
# 2: b 2 /foo/bar

without any warnings.

Arun
  • 116,683
  • 26
  • 284
  • 387