Skip to content
Prev 23055 / 63424 Next

rm() deletes 'c' if c('a','b') is the argument (PR#9399)

That's because you are not using rm() correctly. From the help page:

Arguments:

      ...: the objects to be removed, supplied individually and/or as a
           character vector

     list: a character vector naming objects to be removed.

So if you pass an unnamed argument, rm() will assume you have some 
objects in the .GlobalEnv with those names that you would like to 
remove. If you want to pass a character vector, you have to name it 
because the first argument is '...'.

 > a <- 1:5
 > b <- 2:10
 > c <- "not a good variable name"
 > rm(list=c("a","b"))
 > c
[1] "not a good variable name"

 > a <- 1:5
 > b <- 2:10
 > c <- "still not a good variable name"
 > rm(a,b)
 > c
[1] "still not a good variable name"

 > a <- 1:5
 > b <- 2:10
 > c <- "still not a good variable name"
 > rm("a","b")
 > c
[1] "still not a good variable name"


NB: 'c' is not a good variable name because you are masking an existing 
function.

An argument could be made that the explanation for the first argument is 
not very exact.

Best,

Jim
Steven McKinney wrote: