Skip to content
Prev 23057 / 63421 Next

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

The argument should indeed be made.

I think the documentation for rm() needs
to be changed to:

Arguments:

      ...: the object to be removed, supplied individually.  Multiple objects
           must be supplied via the list argument.
rm    (..., list = character(0), pos = -1,
       envir = as.environment(pos), inherits = FALSE)
Arguments

...	 the objects to be removed, supplied individually and/or as a character vector
[1] "character"
[1] 2
[1] TRUE
By all appearances, c('a', 'b') seems
to be a character vector.  I'm not the
most knowledgeable R programmer, so I'm not
sure what I'm missing here.

I haven't delved deeply into the rm() source code, but
this looks like a logical bug.  The documentation
needs to be modified to fit the current function
behaviour, or the current function behaviour needs
to be modified to fit the documentation.
Warning message:
remove: variable "c" was not found 

Why is "c" ending up in the list of items to remove? 
(see PS: below)
[1] "a" "b"
[1] "character"
[1] TRUE
Warning messages:
1: remove: variable "unlist" was not found 
2: remove: variable "list("a", "b")" was not found
[1] "a"            "b"            "d"            "getMonograph" "last.warning" "myfun"
Does the rm() doc need modification?

Presently it appears that the doc should read

Arguments:

      ...: the object to be removed, supplied individually.  Multiple objects
           must be supplied via the list argument. 




PS:

Does it have anything to do with this
type of behaviour?  Is this essentially
what is happening in the match.call()
in rm()?
[1] "c" "a" "b"
function (..., list = character(0), pos = -1, envir = as.environment(pos), 
    inherits = FALSE) 
{
    names <- sapply(match.call(expand.dots = FALSE)$..., as.character)
    if (length(names) == 0) 
        names <- character(0)
    list <- .Primitive("c")(list, names)
    .Internal(remove(list, envir, inherits))
}
<environment: namespace:base>
a   b 
"a" "b"
[1] "c" "a" "b"
function (definition = NULL, call = sys.call(sys.parent()), expand.dots = TRUE) 
.Internal(match.call(definition, call, expand.dots))
<environment: namespace:base>



Steven McKinney

Statistician
Molecular Oncology and Breast Cancer Program
British Columbia Cancer Research Centre

email: smckinney at bccrc.ca

tel: 604-675-8000 x7561

BCCRC
Molecular Oncology
675 West 10th Ave, Floor 4
Vancouver B.C. 
V5Z 1L3
Canada




-----Original Message-----
From: James W. MacDonald [mailto:jmacdon at med.umich.edu]
Sent: Wed 11/29/2006 11:14 AM
To: Steven McKinney
Cc: hanl2 at wyeth.com; r-devel at stat.math.ethz.ch; R-bugs at biostat.ku.dk
Subject: Re: [Rd] 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: