I often create temporary objects whose names start by \'tp_\' and use user-defined function. In order to keep a clean workspace, I would like to create a function that remov
The pattern argument uses regular expressions. You can use a caret ^
to match the beginning of the string:
rm(list=ls(pattern="^tp_"))
rm(list=setdiff(ls(pattern = "^tp_"), lsf.str()))
However, there are other patterns for managing temporary items / keeping clean workspaces than name prefixes.
Consider, for example,
temp<-new.env()
temp$x <- 1
temp$y <- 2
with(temp,x+y)
#> 3
rm(temp)
Another possibility is attach(NULL,name="temp")
with assign
.