From p.dalgaard at biostat.ku.dk  Mon Nov 17 23:43:22 2008
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Mon, 17 Nov 2008 23:43:22 +0100
Subject: [Rd] assign("FALSE", TRUE)
In-Reply-To: <3EFAB5FA-61AF-4646-8C17-288838AB075B@auckland.ac.nz>
References: <3EFAB5FA-61AF-4646-8C17-288838AB075B@auckland.ac.nz>
Message-ID: <4921F38A.1080201@biostat.ku.dk>

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



[Rd] assign("FALSE", TRUE)
Peter Dalgaard