R/dplyr_inplace.r

Defines functions remove_cols examples.remove_cols

Documented in remove_cols

examples.remove_cols = function() {
  dt = data.table(a=1:3, b=1:3, c=4:6)
  dt
  remove_cols(dt,c("a" ,"b"))
  dt
}

#' Inplace remove columns from a data.table
#' @param dt a data.table
#' @param cols a string with column names
#' @export
remove_cols = function(dt, cols) { 
  for (col in cols) {
    eval(substitute(dt[, col:=NULL], list(col=col)))
  }
  invisible(dt)
}
skranz/dplyrExtras documentation built on May 20, 2020, 6:39 p.m.