Here is the same way as @Nera suggested to check the class first but instead of using .SD
is to use the fast loop of data.table with set
as @Matt Dowle solution with added class check.
for (j in seq_len(ncol(DT))){
if(class(DT[[j]]) == 'factor')
set(DT, j = j, value = as.character(DT[[j]]))
}