[R] The use of F for False and T for True

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Nov 17 10:34:21 CET 2008


Wacek Kusnierczyk wrote:
> Rolf Turner wrote:
>   
>> (Note:  You *cannot* have spurious objects name "FALSE" (and not equal
>> to FALSE) hanging around; R won't let you.  That's why you use FALSE and
>> not F.)
>>     
>
> yes you can, r will let you:
>
> assign("FALSE", TRUE)
> ls()
> # see "FALSE"
> get("FALSE")
> # see TRUE
>
> this does not matter much, as r will think FALSE when you type FALSE,
> rather than look up your variable, and you'd have to use backticks to
> get the latter.  but you may want to be more careful when playing with
> promises and deparsing them in your functions:
>
> f = function(n, m, replace, env) {
>    replace = get(deparse(substitute(replace)), env)
>    sample(1:n, m, replace=replace)
> }
>
> f(n = 10, m = 100, replace = FALSE, env = e)
> # given the above, succeeds
>   
oops,  was too quick.  the following was meant:

f = function(n, m, replace, env) {
   replace = get(deparse(substitute(replace)), env)
   sample(1:n, m, replace=replace)
}

f(n = 10, m = 100, replace = FALSE, env = globalenv())
# given the above, succeeds


or better (i.e., worse):

f = function(n, m, replace, env=parent.frame()) {
   replace = get(deparse(substitute(replace)), env)
   sample(1:n, m, replace=replace)
}

f(n = 10, m = 100, replace = FALSE)
# given the above, succeeds



vQ
(rolf, apologies for the boring pedantry)



More information about the R-help mailing list