-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
(1) setDT modifies the class of the caller object copy too?
> x <- data.frame(a = 1:2)
> foo <- function(z) { setDT(z) ; z[, b:=3:4] ; z }
> y <- foo(x)
> print(class(x))
[1] "data.table" "data.frame"
Note that x's value isn't modified by foo, just its class.
(2) a data.table object is passed as an argument by reference??
> x <- data.table(a = 1:2)
> foo <- function(z) { z[, b:=3:4] }
> y <- foo(x)
> x[]
a b
1: 1 3
2: 2 4
If so this is inconsistent with all other R objects, and seems unlikely to be intentional.
Note this is not about the semantics of data.table operators like := , but rather about the semantics of passing a full data.table object as an argument.
Tested on R3.4/ubuntu14 + R3.6.1/Windows10.
Sample full environment:
> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] d
ata.table_1.12.8
loaded via a namespace (and not attached):
[1] compiler_3.6.1 tools_3.6.1
Metadata
Metadata
Assignees
Labels
No labels