I'd be grateful if someone could explain why, in the example below, the first dt
does not print to the screen, but the second one does.
df <- data.frame(V1=c(1,2),V2=c(11,12))
dt <- data.table(V3=c(4,5),V4=c(44,45))
change <- function(dt,df) {
dt[, V4 := NULL]
df <- df[,-2]
}
change(dt,df)
dt # First dt, nothing printed
dt # Second dt, contents printed as expected
V3
1: 4
2: 5
If I swap the order of the commands in change()
so that
change <- function(dt,df) {
df <- df[,-2]
dt[, V4 := NULL]
}
or if I remove the df
line so that
change <- function(dt,df) {
dt[, V4 := NULL]
}
the unexpected behaviour disappears as the first dt
prints its contents to the screen.
I'm using R version 3.3.2 (2016-10-31) and with data.table version 1.9.6.