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

Duncan Murdoch murdoch at stats.uwo.ca
Wed Nov 29 21:49:00 CET 2006


On 11/29/2006 3:31 PM, p.dalgaard at biostat.ku.dk wrote:
> Steven McKinney wrote:
>> Same behaviour seen on Apple Mac OSX 10.4.8 platform:
>>
>>   
>>> sessionInfo()
>>>     
>> R version 2.4.0 Patched (2006-10-31 r39758) 
>> powerpc-apple-darwin8.8.0 
>>
>> locale:
>> en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
>>
>> attached base packages:
>> [1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"  "base"     
>>
>> other attached packages:
>>     XML 
>> "1.2-0" 
>>   
>>> ls()
>>>     
>> [1] "getMonograph" "last.warning" "myfun"       
>>   
>>> a <- 1
>>> b <- 2
>>> c <- letters
>>> a
>>>     
>> [1] 1
>>   
>>> b
>>>     
>> [1] 2
>>   
>>> c
>>>     
>>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
>>   
>>> rm(c('a', 'b'))
>>> a
>>>     
>> Error: object "a" not found
>>   
>>> b
>>>     
>> Error: object "b" not found
>>   
>>> c
>>>     
>> .Primitive("c")
>>   
>>> ls()
>>>     
>> [1] "getMonograph" "last.warning" "myfun"       
>>   
>>> a <- 1
>>> b <- 2
>>> d <- letters
>>> ls()
>>>     
>> [1] "a"            "b"            "d"            "getMonograph" "last.warning" "myfun"       
>>   
>>> rm(c('a', 'b'))
>>>     
>> Warning message:
>> remove: variable "c" was not found 
>>   
>>> ls()
>>>     
>> [1] "d"            "getMonograph" "last.warning" "myfun"       
>>   
>>
>> 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: r-devel-bounces at r-project.org on behalf of hanl2 at wyeth.com
>> Sent: Wed 11/29/2006 10:35 AM
>> To: r-devel at stat.math.ethz.ch
>> Cc: R-bugs at biostat.ku.dk
>> Subject: [Rd] rm() deletes 'c' if c('a','b') is the argument (PR#9399)
>>  
>> Full_Name: Lixin Han
>> Version: 2.4.0
>> OS: Windows 2000
>> Submission from: (NULL) (155.94.110.222)
>>
>>
>> A character vector c('a','b') is supplied to rm().  As a result, 'c' is deleted
>> unintentionally.
>>
>>   
>>> a <- 1:5
>>> b <- 'abc'
>>> c <- letters
>>> ls()
>>>     
>> [1] "a" "b" "c"
>>   
>>> rm(c('a','b'))
>>> ls()
>>>     
>> character(0)
>>   
>>
>>   
> The reason is that
>  > x <- function(...) sapply(match.call(expand.dots = FALSE)$..., 
> as.character)
>  > x(c(a,b))
>      [,1]
> [1,] "c"
> [2,] "a"
> [3,] "b"
> 
> Which in turn happens because
>  > as.character(quote(c(a,b)))
> [1] "c" "a" "b"
> 
> I don't know if it really qualifies as a bug, but it's not documented 
> that as.character() is used and I suppose we could be more careful with 
> the argument checking.

I'd say it qualifies as a bug if we remove something that the user 
didn't ask to have removed.   A user would have a right to be annoyed if

rm( NotNeeded("a", "b") )

(where NotNeeded was a function to give the subset of variables which 
are not needed) went ahead and removed all the variables, *plus* the 
NotNeeded function!

Duncan Murdoch



More information about the R-devel mailing list