The use of F for False and T for True

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

The use of F for False and T for True

David Howell-2
Sampling with and without replacement

I seem unable to use "replace = F" when I want to sample without
replacement. I would think
that it comes down to "F is not a legitimate abbreviation for FALSE."
except that
Dalgaard (p. 118) uses F for FALSE and it works
 "pairwise.t.test(folate, ventilation, pool.sd = F)"

I am having trouble when I try to sample a vector without replacement.

The following code illustrates my problem.

 >b <- c(1:8)

 >sample(b)
[1] 7 8 3 5 1 6 2 4    # That works correctly--no replacement
  (This would be my preferred form, but when I look at the code later it
is helpful to know
  explicitly how I did the sampling.)

 > sample(b, replace = T)
[1] 7 5 6 2 5 5 4 7    # That is also correct--replacement

 > sample(b, replace = F)
[1] 1 7 3 7 3 4 6 5    # There are two 3s and two 7s, so there was
replacement


 >sample(b, replace = FALSE)
[1] 8 1 3 2 5 6 7 4    # That works just fine

 >sample(b, replace = "F")
[1] 5 3 2 8 4 1 7 6     # quoting the F is fine.


If it is OK to replace TRUE with T, why can't I replace FALSE with F?

 
 I have a similar problem if I write data <= read.table(file.choose(),
header = F)
 
 I'm using a Windows machine with version 2.8.0, but I'm sure that this
is not a machine specific problem.
 Thanks,
 Dave Howell

--
David C. Howell
PO Box 770059
627 Meadowbrook Circle
Steamboat Springs, CO
80477

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Rolf Turner

On 17/11/2008, at 1:56 PM, David C. Howell wrote:

> Sampling with and without replacement
>
> I seem unable to use "replace = F" when I want to sample without
> replacement. I would think
> that it comes down to "F is not a legitimate abbreviation for FALSE."
> except that
> Dalgaard (p. 118) uses F for FALSE and it works
>  "pairwise.t.test(folate, ventilation, pool.sd = F)"
>
> I am having trouble when I try to sample a vector without replacement.
>
> The following code illustrates my problem.

        <snip>

(a) Naughty Peter.  It works, but is ill-advised.  The difference is
that FALSE is a reserved word (as is TRUE) but F and T are *not*  
reserved.

(b) Try find("F") --- I conjecture that you have an object named "F"
(not equal to FALSE) floating around somewhere in your search path.


Remove or rename this, and your ``replace=F'' will work.

But .... ***DON'T DO THAT***!!!

Use FALSE when you mean FALSE.  Don't use F.  It causes trouble.

(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.)

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Simon Blomberg-4
In reply to this post by David Howell-2
It is better programming practice to use FALSE for false and TRUE for
true, and not F and T. This is because it is quite legal to do this:

T <- FALSE
F <- TRUE

or any other assignment. If you re-assign T or F (which are set to TRUE
and FALSE at the beginning of a session), you run into the sort of
problem that you have discovered.

Also, there is the F and t distributions, and the t() function, so
having variables called F and T may lead to further confusion. If you
mean FALSE, say FALSE. If you mean TRUE, say TRUE.

Cheers,

Simon.

On Sun, 2008-11-16 at 17:56 -0700, David C. Howell wrote:

> Sampling with and without replacement
>
> I seem unable to use "replace = F" when I want to sample without
> replacement. I would think
> that it comes down to "F is not a legitimate abbreviation for FALSE."
> except that
> Dalgaard (p. 118) uses F for FALSE and it works
>  "pairwise.t.test(folate, ventilation, pool.sd = F)"
>
> I am having trouble when I try to sample a vector without replacement.
>
> The following code illustrates my problem.
>
>  >b <- c(1:8)
>
>  >sample(b)
> [1] 7 8 3 5 1 6 2 4    # That works correctly--no replacement
>   (This would be my preferred form, but when I look at the code later it
> is helpful to know
>   explicitly how I did the sampling.)
>
>  > sample(b, replace = T)
> [1] 7 5 6 2 5 5 4 7    # That is also correct--replacement
>
>  > sample(b, replace = F)
> [1] 1 7 3 7 3 4 6 5    # There are two 3s and two 7s, so there was
> replacement
>
>
>  >sample(b, replace = FALSE)
> [1] 8 1 3 2 5 6 7 4    # That works just fine
>
>  >sample(b, replace = "F")
> [1] 5 3 2 8 4 1 7 6     # quoting the F is fine.
>
>
> If it is OK to replace TRUE with T, why can't I replace FALSE with F?
>
>  
>  I have a similar problem if I write data <= read.table(file.choose(),
> header = F)
>  
>  I'm using a Windows machine with version 2.8.0, but I'm sure that this
> is not a machine specific problem.
>  Thanks,
>  Dave Howell
>
--
Simon Blomberg, BSc (Hons), PhD, MAppStat.
Lecturer and Consultant Statistician
Faculty of Biological and Chemical Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer can
be extracted from a given body of data. - John Tukey.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Wacek Kusnierczyk
In reply to this post by Rolf Turner
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


this is a rather silly example and you're unlikely to meet the problem
in practice, but it is *not* impossible.  knowing only the interface to
f and not its implementation may lead you to an incorrect assumption
about the meaning of FALSE inside f.

vQ

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Wacek Kusnierczyk
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)

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Peter Dalgaard
In reply to this post by Rolf Turner
Rolf Turner wrote:

>
> On 17/11/2008, at 1:56 PM, David C. Howell wrote:
>
>> Sampling with and without replacement
>>
>> I seem unable to use "replace = F" when I want to sample without
>> replacement. I would think
>> that it comes down to "F is not a legitimate abbreviation for FALSE."
>> except that
>> Dalgaard (p. 118) uses F for FALSE and it works
>>  "pairwise.t.test(folate, ventilation, pool.sd = F)"

> (a) Naughty Peter.  It works, but is ill-advised.  The difference is
> that FALSE is a reserved word (as is TRUE) but F and T are *not* reserved.

Yeah I know, tell users to type until their fingers fall off... In my
defense the point is actually made on p.12 (both editions) and can be
found via "FALSE" in the index.



--
   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
~~~~~~~~~~ - ([hidden email])              FAX: (+45) 35327907

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

hadley wickham
In reply to this post by Simon Blomberg-4
On Sun, Nov 16, 2008 at 7:41 PM, Simon Blomberg <[hidden email]> wrote:
> It is better programming practice to use FALSE for false and TRUE for
> true, and not F and T. This is because it is quite legal to do this:
>
> T <- FALSE
> F <- TRUE

It may be better programming practice, but is it better interactive
data analysis practice?  R isn't just a programming language, and
there are lots of good reasons to provide shortcuts that reduce
typing.  It's very easy to forget that most people can't touch type at
a decent speed, and every key press less helps them get their ideas
from their head to the computer faster.

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Duncan Murdoch
On 17/11/2008 8:03 AM, hadley wickham wrote:

> On Sun, Nov 16, 2008 at 7:41 PM, Simon Blomberg <[hidden email]> wrote:
>> It is better programming practice to use FALSE for false and TRUE for
>> true, and not F and T. This is because it is quite legal to do this:
>>
>> T <- FALSE
>> F <- TRUE
>
> It may be better programming practice, but is it better interactive
> data analysis practice?  R isn't just a programming language, and
> there are lots of good reasons to provide shortcuts that reduce
> typing.  It's very easy to forget that most people can't touch type at
> a decent speed, and every key press less helps them get their ideas
> from their head to the computer faster.

That would be an argument for T and F being the reserved words (as I
think they are in S-PLUS).  But since it's so easy to use T or F as a
variable, the problems caused by using them as TRUE or FALSE are not
negligible -- look at the original question in this thread, which was
likely caused by using F as a variable.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Portected? Variable assignment? Was RE: The use of F for False and T for True

Lucke, Joseph F
 
The TRUE/FALSE vs. T/F issue brings up a related one.  Can one assign a
variable a value during an R session that cannot be re-assigned any new
value during the session?  That is, the variable is `protected' from
change during the session.  `Session' here is not  precisely defined, so
that will induce some problems.  A reference to this problem would be
sufficient.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Portected? Variable assignment? Was RE: The use of F for False and T for True

Martin Morgan
"Lucke, Joseph F" <[hidden email]> writes:

>  
> The TRUE/FALSE vs. T/F issue brings up a related one.  Can one assign a
> variable a value during an R session that cannot be re-assigned any new
> value during the session?  That is, the variable is `protected' from
> change during the session.  `Session' here is not  precisely defined, so

Environments and their bindings can be locked.

> env <- new.env(parent=emptyenv())
> env[["x"]] <- 10
> lockBinding(env=env, sym="x")
> env[["x"]] <- 11
Error in env[["x"]] <- 11 : cannot change value of locked binding for 'x'

Martin

> that will induce some problems.  A reference to this problem would be
> sufficient.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Portected? Variable assignment? Was RE: The use of F for False and T for True

Luke Tierney
In reply to this post by Lucke, Joseph F
Have a look at ?lockBinding

Best,

luke

On Mon, 17 Nov 2008, Lucke, Joseph F wrote:

>
> The TRUE/FALSE vs. T/F issue brings up a related one.  Can one assign a
> variable a value during an R session that cannot be re-assigned any new
> value during the session?  That is, the variable is `protected' from
> change during the session.  `Session' here is not  precisely defined, so
> that will induce some problems.  A reference to this problem would be
> sufficient.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Henrik Bengtsson
In reply to this post by Duncan Murdoch
To save my fingers and still being on the safe side, I always do:

> !0
[1] TRUE
> !1
[1] FALSE

;)  ...still hackable though.

/Henrik

On Mon, Nov 17, 2008 at 5:25 AM, Duncan Murdoch <[hidden email]> wrote:

> On 17/11/2008 8:03 AM, hadley wickham wrote:
>>
>> On Sun, Nov 16, 2008 at 7:41 PM, Simon Blomberg <[hidden email]>
>> wrote:
>>>
>>> It is better programming practice to use FALSE for false and TRUE for
>>> true, and not F and T. This is because it is quite legal to do this:
>>>
>>> T <- FALSE
>>> F <- TRUE
>>
>> It may be better programming practice, but is it better interactive
>> data analysis practice?  R isn't just a programming language, and
>> there are lots of good reasons to provide shortcuts that reduce
>> typing.  It's very easy to forget that most people can't touch type at
>> a decent speed, and every key press less helps them get their ideas
>> from their head to the computer faster.
>
> That would be an argument for T and F being the reserved words (as I think
> they are in S-PLUS).  But since it's so easy to use T or F as a variable,
> the problems caused by using them as TRUE or FALSE are not negligible --
> look at the original question in this thread, which was likely caused by
> using F as a variable.
>
> Duncan Murdoch
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Gabor Grothendieck
How about

!!0 # FALSE
!!1 # TRUE

Although its one more char, its very easy to press ! twice and when you
look at it its more obvious since 0 is associated with FALSE and
1 with TRUE.

On Mon, Nov 17, 2008 at 12:42 PM, Henrik Bengtsson <[hidden email]> wrote:

> To save my fingers and still being on the safe side, I always do:
>
>> !0
> [1] TRUE
>> !1
> [1] FALSE
>
> ;)  ...still hackable though.
>
> /Henrik
>
> On Mon, Nov 17, 2008 at 5:25 AM, Duncan Murdoch <[hidden email]> wrote:
>> On 17/11/2008 8:03 AM, hadley wickham wrote:
>>>
>>> On Sun, Nov 16, 2008 at 7:41 PM, Simon Blomberg <[hidden email]>
>>> wrote:
>>>>
>>>> It is better programming practice to use FALSE for false and TRUE for
>>>> true, and not F and T. This is because it is quite legal to do this:
>>>>
>>>> T <- FALSE
>>>> F <- TRUE
>>>
>>> It may be better programming practice, but is it better interactive
>>> data analysis practice?  R isn't just a programming language, and
>>> there are lots of good reasons to provide shortcuts that reduce
>>> typing.  It's very easy to forget that most people can't touch type at
>>> a decent speed, and every key press less helps them get their ideas
>>> from their head to the computer faster.
>>
>> That would be an argument for T and F being the reserved words (as I think
>> they are in S-PLUS).  But since it's so easy to use T or F as a variable,
>> the problems caused by using them as TRUE or FALSE are not negligible --
>> look at the original question in this thread, which was likely caused by
>> using F as a variable.
>>
>> Duncan Murdoch
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: The use of F for False and T for True

Simon Blomberg-4
In reply to this post by hadley wickham
Fair enough. But I find my interactive data analysis jobs quickly get
big enough (data manipulation, a series of model fits, some customised
output) for the analysis script to turn into something that looks like a
program. Of course, YMMV. I also get annoyed at code that uses = for
assignment outside function calls. So I may be a bit pedantic when it
comes to coding style. But I still believe that good style is worth
aiming for. Should R assume some basic proficiency in touch typing? :-)

Cheers,

Simon.

On Mon, 2008-11-17 at 07:03 -0600, hadley wickham wrote:

> On Sun, Nov 16, 2008 at 7:41 PM, Simon Blomberg <[hidden email]> wrote:
> > It is better programming practice to use FALSE for false and TRUE for
> > true, and not F and T. This is because it is quite legal to do this:
> >
> > T <- FALSE
> > F <- TRUE
>
> It may be better programming practice, but is it better interactive
> data analysis practice?  R isn't just a programming language, and
> there are lots of good reasons to provide shortcuts that reduce
> typing.  It's very easy to forget that most people can't touch type at
> a decent speed, and every key press less helps them get their ideas
> from their head to the computer faster.
>
> Hadley
>
--
Simon Blomberg, BSc (Hons), PhD, MAppStat.
Lecturer and Consultant Statistician
Faculty of Biological and Chemical Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer can
be extracted from a given body of data. - John Tukey.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.