From maechler at stat.math.ethz.ch  Mon Nov 17 23:11:36 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Mon, 17 Nov 2008 23:11:36 +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: <18721.60440.551783.840625@cmath-5.math.ethz.ch>

>>>>> "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



[Rd] assign("FALSE", TRUE)
Martin Maechler