Don't want original data.table to be modified when passed to a function
问题 I am a fan of data.table , as of writing re-usable functions for all current and future needs. Here's a challenge I run into while working on the answer to this problem: Best way to plot automatically all data.table columns using ggplot2 We pass data.table to a function for plotting and then the original data.table gets modified, even though we made a copy of it to prevent that. Here's a simple code to illustrate: plotYofX <- function(.dt,x,y) { dt <- .dt dt[, (c(x,y)) := lapply(.SD, function