Given a function
testf <- function(dt){
dt[, t := seq(1:nrow(dt))]
return(dt)
}
and the data.table:
dt <- data.table(a=1, b=2)
when applying the function on this data.table and not assigning the output to a variable there is for some reason I don't understand no visible output generated.
testf(dt)
#nothing
hoewever, when take the same function but with a print function before it does:
testf <- function(dt){
dt[, t := seq(1:nrow(dt))]
print(dt)
return(dt)
}
testd(dt)
a b t
1: 1 2 1
a b t
1: 1 2 1
When assigning the Output to a variable the output is however actually stored in that variable, no matter whether a print() function is called within the function or not:
t <- testf(dt)
View(t)
#Output visible
Can anybody explain me what is going wrong here?