Skip to content

Instantly share code, notes, and snippets.

@nbenn
Created October 25, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbenn/86e6585e3014f127d6c5cb30c83d2a96 to your computer and use it in GitHub Desktop.
Save nbenn/86e6585e3014f127d6c5cb30c83d2a96 to your computer and use it in GitHub Desktop.
Ad SO #52974000
rm_tbl_4 <- function(tbl, env) {
tbl = deparse(substitute(tbl))
rm(list = tbl, pos = env)
}
fun_a <- function(dat_tbl) {
fun_b(dat_tbl)
}
fun_b <- function(data_table) {
rm_tbl_4(data_table, environment())
}
dt <- data.table(a = 1:3, b = 2:4)
fun_a(dt)
dt
@trafficonese
Copy link

trafficonese commented Oct 25, 2018

rm_tbl_4 <- function(tbl, env) {
  print(paste("rm_tb", address(tbl)))
  rm(list = tbl, pos = env)
}

fun_b <- function(data_table) {
  print(paste("fun_b", address(data_table)))
  rm_tbl_4(data_table, ".GlobalEnv")
}

fun_a <- function(dat_tbl) {
  dat_tbl = deparse(substitute(dat_tbl))
  print(paste("fun_a", address(dt)))
  fun_b(dat_tbl)
}

dt <- data.table(a = 1:3, b = 2:4)
address(dt)
fun_a(dt)
dt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment