I have a (big-ish) data.table
. And I want to do the same thing to many of its columns. Say,
dt <- data.table( ltr = letters[1:5] )
func <- function( dt ){
cols <- colnames( dt ) # Columns to apply op to
dt[ , (cols) := lapply( .SD, toupper ), .SDcols = cols ]
return( dt )
}
The function func
converts characters to upper case for all columns. I try
func( dt )
I get the error
Error in `:=`((cols), lapply(.SD, toupper)) :
Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
I'm still not sure what causes the error and have read help(":=")
, the FAQs and some other (SO) sources. Any help?
NOTE: I should have given more details about the context. func
is a function written in a package. That makes all the difference