[Rd] assign("FALSE", TRUE)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Nov 17 23:43:22 CET 2008


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



More information about the R-devel mailing list