It was recently pointed out by Wacek Kusnierczyk that although one is prevented from doing FALSE <- TRUE one *can* do assign("FALSE",TRUE) and have an object named ``FALSE'' with value TRUE in one's workspace. This apparently has no deleterious effects; e.g. doing sample(1:7,replace=FALSE) gives a random permutation of 1:7 as expected and desired. I.e. the local object named ``FALSE'' is not used. Still, this seems counterintuitive and a bit confusing. Is it the intended state of affairs? I would have thought that FALSE <- <whatever> and assign("FALSE",<whatever>) would be completely equivalent. This is clearly not a very important issue, but it might bear some thinking about. cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
>>>>> "RT" == Rolf Turner <r.turner at auckland.ac.nz> >>>>> on Tue, 18 Nov 2008 08:49:21 +1300 writes:RT> It was recently pointed out by Wacek Kusnierczyk that RT> although one is prevented from doing RT> FALSE <- TRUE RT> one *can* do RT> assign("FALSE",TRUE) RT> and have an object named ``FALSE'' with value TRUE in RT> one's workspace. RT> This apparently has no deleterious effects; e.g. doing RT> sample(1:7,replace=FALSE) RT> gives a random permutation of 1:7 as expected and RT> desired. I.e. the local object named ``FALSE'' is not RT> used. RT> Still, this seems counterintuitive and a bit confusing. RT> Is it the intended state of affairs? I would have RT> thought that RT> FALSE <- <whatever> RT> and RT> assign("FALSE",<whatever>) RT> would be completely equivalent. Yes, such thoughts are understandable but wrong as you now know. Clearly assign("a b c", "abc") does work, but a b c <- "abc" does not; only `a b c` <- "abc" does, as well as `FALSE` <- TRUE .... and Wacek did mention the backticks. But in spite of all that I agree that I'd have liked `FALSE` <- <whatever> to signal an error about the fact that it is a reserved word. RT> This is clearly not a very important issue, but it might RT> bear some thinking about. Yes. I'd propose that R-core look into how to make assignment to a reserved word an error. Thank you, Rolf, Martin
Rolf Turner wrote:> > It was recently pointed out by Wacek Kusnierczyk that although one is > prevented from doing > > FALSE <- TRUE > > one *can* do > > assign("FALSE",TRUE) > > and have an object named ``FALSE'' with value TRUE in one's workspace. > > This apparently has no deleterious effects; e.g. doing > > sample(1:7,replace=FALSE) > > gives a random permutation of 1:7 as expected and desired. I.e. the > local object named ``FALSE'' is not used. > > Still, this seems counterintuitive and a bit confusing. Is it the intended > state of affairs? I would have thought that > > FALSE <- <whatever> > > and > > assign("FALSE",<whatever>) > > would be completely equivalent.No, FALSE is a _keyword_ representing the logical value. > e <- quote(`FALSE` & FALSE) > e[[2]] `FALSE` > e[[3]] [1] FALSE > mode(e[[3]]) [1] "logical" > mode(e[[2]]) [1] "name" The thing that is equivalent to assign("FALSE",<whatever>) is `FALSE`<-whatever. There are a couple of other keywords: TRUE, if, else, for, while, repeat, next, break, function. Did I forget any? The stuff you can do with FALSE isn't really any stranger than > `2` <- pi > 2+2 [1] 4 so that two and two remains four for any value of `2`. You can't do 2<-pi anymore than you can do FALSE<-foo.> > This is clearly not a very important issue, but it might bear some > thinking about.-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Possibly Parallel Threads
- [Fwd: Re: [R] Randomly remove condition-selected rows from a matrix]
- if does not covert raw to logical (PR#13630)
- odd behaviour of identical
- actual argument matching does not conform to the definition (PR#13634)
- duplicated fails to rise correct errors (PR#13632)