I would like to create a function (CleanEnvir) which basically calls remove/rm and which removes certain objects from .GlobalEnv.
CleanEnvir
.GlobalEnv
Cle
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()) }