hanl2 at wyeth.com
2006-Nov-29 18:35 UTC
[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)>
Steven McKinney
2006-Nov-29 18:44 UTC
[Rd] rm() deletes 'c' if c('a','b') is the argument (PR#9399)
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')) > aError: object "a" not found> bError: 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)>______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Lixin Han
2006-Nov-29 19:24 UTC
[Rd] rm() deletes 'c' if c('a','b') is the argument (PR#9399)
However, the help page also states: ...the objects to be removed, supplied individually and/or as a character vector So maybe the help page needs to be changed. Lixin Han Lixin Han, PhD Sr. Principal Biostatistician Wyeth Research 35 Cambridgepark Drive Cambridge, MA 02140 Phone: (617) 665-8642 Fax: (617) 665-8007 hanl2@wyeth.com>>> "James W. MacDonald" <jmacdon@med.umich.edu> 11/29/2006 2:14 PM >>>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:> 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@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@r-project.org on behalf of hanl2@wyeth.com > Sent: Wed 11/29/2006 10:35 AM > To: r-devel@stat.math.ethz.ch > Cc: R-bugs@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) > > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ********************************************************** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues. [[alternative HTML version deleted]]
p.dalgaard at biostat.ku.dk
2006-Nov-29 20:31 UTC
[Rd] rm() deletes 'c' if c('a','b') is the argument (PR#9399)
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.
bill at insightful.com
2006-Nov-29 22:04 UTC
[Rd] rm() deletes 'c' if c('a','b') is the argument (PR#9399)
On Wed, 29 Nov 2006 p.dalgaard at biostat.ku.dk wrote:> > 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) > ... > 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 suggest that if any changes are made, then rm(c('a','b')) should throw an error. Functions which try to be "user-friendly" by letting you omit quotes are generally a bad idea, IMO. They all need patching up in various ways to work in all situation (e.g., library's character.only=TRUE argument and the complicated code in help to see what the topic really is). Perhaps rm() should be deprecated in favor of remove(), which uses standard S syntax rules. ---------------------------------------------------------------------------- Bill Dunlap Insightful Corporation bill at insightful dot com 360-428-8146 "All statements in this message represent the opinions of the author and do not necessarily reflect Insightful Corporation policy or position."