title: Why does is.na() return TRUE on the first element of an empty vector in R?
body: <p>So I was requested to write a function that returns a vector (specifically a character vector).
  When the vector is NA I should print something.
  When I check a vector that I know is empty:</p>
  <pre><code>is.na(foo)
  </code></pre>
  <p>I get -</p>
  <pre><code>logical(0)
  </code></pre>
  <p>but when I check:</p>
  <pre><code>is.na(foo[1])
  </code></pre>
  <p>I get</p>
  <pre><code>TRUE
  </code></pre>
  <p>Why is that?</p>
  <p><strong>Edit</strong> -</p>
  <p>Was asked what is my source of <code>foo</code>:</p>
  <p>It's from that function <code>filter</code> from the library <code>dplyr</code></p>
  <pre><code>state_name_vec &lt;- filter(uscities, city == city_name)$state_name
  </code></pre>
  <p>I can get a character vector, a character (i.e. a string in other languages) or, I guess, an empty character vector. I presume I can also get a data.frame, but in my case, I don't.</p>
  <p>I have tried to understand what does the type <code>.data</code> mean, which filter returns.</p>
  <p><a href="https://i.stack.imgur.com/iP74z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iP74z.png" alt="https://dplyr.tidyverse.org/reference/filter.html#:~:text=The%20filter()%20function%20is,%2C%20unlike%20base%20subsetting%20with%20%5B%20." /></a></p>
  <p>After googling, I got this:</p>
  <p><a href="https://i.stack.imgur.com/1DPDm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1DPDm.png" alt="https://cran.r-project.org/web/packages/dplyr/vignettes/programming.html" /></a></p>
  <p>So I guess my question is what happens when <code>.data</code> is empty?</p>