[Rd] assign("FALSE", TRUE)
Martin Maechler
maechler at stat.math.ethz.ch
Mon Nov 17 23:11:36 CET 2008
>>>>> "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
More information about the R-devel
mailing list