Remove objects in .GlobalEnv from within a function

前端 未结 3 1840
庸人自扰
庸人自扰 2021-02-07 16:35

I would like to create a function (CleanEnvir) which basically calls remove/rm and which removes certain objects from .GlobalEnv.

  Cle         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-07 17:08

    You need to do your search in the Global Env as well as the removal there:

    CleanEnvir <- function(pattern = "tmp"){
          rm(list = ls(envir=globalenv())[
                 grep("tmp", ls(envir=globalenv()))], envir = globalenv())
      }
    

提交回复
热议问题