title: Testing whether a value is equal to a string value when it can also be NULL
body: <p>I have a value which can be one of 3 strings, or <code>NULL</code>. When the value is <code>NULL</code> the following code does not work</p>
  <pre><code>value &lt;- NULL
  
  if( value == &quot;test&quot; ){
      print(&quot;1&quot;)
  } else {
      print(&quot;2&quot;)
  }
  </code></pre>
  <p>It seems I have to write the code as below to make it work:</p>
  <pre><code>if ( !is.null(value) &amp;&amp; value== &quot;test&quot; ) {
      print(&quot;1&quot;)
  } else {
      print(&quot;2&quot;)
  }
  </code></pre>
  <p>Writing it like that however seems unnecessarily complicated and messy.</p>
  <p>Is there a cleaner way to do this?</p>