Skip to content

Instantly share code, notes, and snippets.

@nbenn

nbenn/rm-obj.R

Created Oct 25, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@trafficonese 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
You can’t perform that action at this time.