title: R: why does matching character "NULL" for function argument cause unexpected results?
body: <p>The R code below produces unexpected results. (I put <code>NULL</code> in <code>b</code> just for testing. My interest is the character <strong>"NULL"</strong>)</p>
  
  <pre><code>f &lt;- function(a, b = c('x', 'NULLL', NULL)) {
    print(a)
    b &lt;- match.arg(b)
    print(class(b))
    print(b)
    print(b == 'NULL')
    print(b == "NULL")
    print(is.null(b))
  
  }
  f(2)
  f(2, 'x')
  f(2, 'NULL') 
  </code></pre>
  
  <p>The results look like following. I assume for <code>f(2, 'NULL')</code>, there should be <code>'TRUE</code>' printed out, shouldn't it? Really strange to me! Any explanations? Thanks a lot!</p>
  
  <pre><code>R 3.2.3&gt; f(2)
  [1] 2
  [1] "character"
  [1] "x"
  [1] FALSE
  [1] FALSE
  [1] FALSE
  R 3.2.3&gt; f(2, 'x')
  [1] 2
  [1] "character"
  [1] "x"
  [1] FALSE
  [1] FALSE
  [1] FALSE
  R 3.2.3&gt; f(2, 'NULL')
  [1] 2
  [1] "character"
  [1] "NULLL"
  [1] FALSE
  [1] FALSE
  [1] FALSE
  </code></pre>