Remove multiple objects with rm()

后端 未结 4 981
日久生厌
日久生厌 2020-11-28 03:56

My memory is getting clogged by a bunch of intermediate files (call them temp1, temp2, etc). Is it possible to remove them from memory without doing rm(temp1),

4条回答
  •  醉梦人生
    2020-11-28 04:12

    Or using regular expressions

    "rmlike" <- function(...) {
      names <- sapply(
        match.call(expand.dots = FALSE)$..., as.character)
      names = paste(names,collapse="|")
      Vars <- ls(1)
      r <- Vars[grep(paste("^(",names,").*",sep=""),Vars)]
      rm(list=r,pos=1)
    }
    
    rmlike(temp)
    

提交回复
热议问题