How do you check for a scalar in R?
<p>I am interested identifying numeric scalars like:</p>

<pre><code>doub &lt;- 3.14
intg &lt;- 8L
</code></pre>

<p>I know that these are treated as length one vectors. Thus, for any R object <code>x</code>, is <code>is.vector(x) &amp;&amp; length(x) == 1</code> the right way to check whether <code>x</code> is a scalar? <code>length(x) == 1</code> by itself is not sufficient as it returns a true, when it should return false, for a data frame with one column or a list with one element.</p>

<p>Is there a reason why there is no such function <code>is.scalar</code> implemented in base <code>R</code>? For some reason the two I could find in other functions fail for the data frame case mentioned previously, these are:</p>

<pre><code>assertthat::is.scalar(data.frame(a = 1:2))
lambda.tools::is.scalar(data.frame(a = 1:2))
</code></pre>

<p>Why are the results of these two function calls different to my understanding (and definition) of how a <code>is.scalar</code> function should work?</p>