I would like to delete all global variables except a defined environment with variables in it.
Say I have the following:
my.env = new.env()
assign("a", 123, envir = my.env)
my.env$somestring = "Variable mat as vector string"
And also some global variables:
Age <- as.numeric(42)
HbA <- as.numeric(2)
WHR <- as.numeric(1.3)
I know I can delete all global variables but one with setdiff
setdiff(ls(),'Age')
#[1] "HbA" "my.env" "WHR"
but when I call the following I get an error. This is expected because my.env
is actually a pointer, if I am not mistaken
setdiff(ls(), my.env)
#Error in as.vector(x, mode) :
# cannot coerce type 'environment' to vector of type 'any'
How can I delete all variables but keep my.env
? (with the variables in it)