Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is documented on <code>?logical</code>. The pertinent section of which is:</p> <pre><code>Details: ‘TRUE’ and ‘FALSE’ are reserved words denoting logical constants in the R language, whereas ‘T’ and ‘F’ are global variables whose initial values set to these. All four are ‘logical(1)’ vectors. Logical vectors are coerced to integer vectors in contexts where a numerical value is required, with ‘TRUE’ being mapped to ‘1L’, ‘FALSE’ to ‘0L’ and ‘NA’ to ‘NA_integer_’. </code></pre> <p>The second paragraph there explains the behaviour you are seeing, namely <code>5 == 1L</code> and <code>5 == 0L</code> respectively, which should both return <code>FALSE</code>, where as <code>1 == 1L</code> and <code>0 == 0L</code> should be TRUE for <code>1 == TRUE</code> and <code>0 == FALSE</code> respectively. I believe these are not testing what you want them to test; the comparison is on the basis of the numerical representation of <code>TRUE</code> and <code>FALSE</code> in R, i.e. what numeric values they take when coerced to numeric.</p> <p>However, only <code>TRUE</code> is guaranteed to the be <code>TRUE</code>:</p> <pre><code>&gt; isTRUE(TRUE) [1] TRUE &gt; isTRUE(1) [1] FALSE &gt; isTRUE(T) [1] TRUE &gt; T &lt;- 2 &gt; isTRUE(T) [1] FALSE </code></pre> <p><code>isTRUE</code> is a wrapper for <code>identical(x, TRUE)</code>, and from <code>?isTRUE</code> we note:</p> <pre><code>Details: .... ‘isTRUE(x)’ is an abbreviation of ‘identical(TRUE, x)’, and so is true if and only if ‘x’ is a length-one logical vector whose only element is ‘TRUE’ and which has no attributes (not even names). </code></pre> <p>So by the same virtue, only <code>FALSE</code> is guaranteed to be exactly equal to <code>FALSE</code>.</p> <pre><code>&gt; identical(F, FALSE) [1] TRUE &gt; identical(0, FALSE) [1] FALSE &gt; F &lt;- "hello" &gt; identical(F, FALSE) [1] FALSE </code></pre> <p>If this concerns you, always use <code>isTRUE()</code> or <code>identical(x, FALSE)</code> to check for equivalence with <code>TRUE</code> and <code>FALSE</code> respectively. <code>==</code> is not doing what you think it is.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload