1

ls() gives among others and the following object: object2remove

Next we have the following code:

variableIuse <- "object2remove"

The question is:

How do I remove implicitly object2remove through the variableIuse?

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
apostolos
  • 63
  • 3
  • This is a very simple extension of your previous question: [Implicit variable reference in R](http://stackoverflow.com/questions/6433825/implicit-variable-reference-in-r) – Joshua Ulrich Jun 22 '11 at 17:40

1 Answers1

5

You need to use the list parameter of the rm() function:

> object2remove <- 1:10
> variableIuse <- 'object2remove'
> rm(list = variableIuse) # remove variable named by variableIuse
> variableIuse            # still exists
[1] "object2remove"
> object2remove           # no longer exists
Error: object 'object2remove' not found
Prasad Chalasani
  • 19,912
  • 7
  • 51
  • 73