title: Using rpois and rnbinom with dplyr commands
body: <p>I am trying to generate random numbers within a tibble where different categories of item are distributed differently.  I'm not having much luck.  Here's the code and the error it produces:</p>
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  
  letters &lt;- tibble(letter = c(rep(&quot;A&quot;, 5), rep(&quot;B&quot;, 5), rep(&quot;C&quot;, 5) ))
  
  letters %&gt;%
    rowwise() %&gt;%
    mutate(Proj = case_when(
      letter == &quot;A&quot; ~ rpois(1, lambda = .7746),
      letter == &quot;B&quot; ~ rnbinom(1, size = 3.3848, mu = 1.2),
      letter == &quot;C&quot; ~ rpois(1, lambda = .5057)
    ))
  
  #&gt; Error in `mutate()`:
  #&gt; ! Problem while computing `Proj = case_when(...)`.
  #&gt; ℹ The error occurred in row 1.
  #&gt; Caused by error in `` names(message) &lt;- `*vtmp*` ``:
  #&gt; ! 'names' attribute [1] must be the same length as the vector [0]
  </code></pre>
  <p>Interestingly, the code works just fine if I use continuous distributions instead of discrete distributions.</p>
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  
  letters &lt;- tibble(letter = c(rep(&quot;A&quot;, 5), rep(&quot;B&quot;, 5), rep(&quot;C&quot;, 5) ))
  
  letters %&gt;%
    rowwise() %&gt;%
    mutate(Proj = case_when(
      letter == &quot;A&quot; ~ rweibull(1, shape = 2.3487, scale = 8.174),
      letter == &quot;B&quot; ~ rexp(1, rate = .0442),
      letter == &quot;C&quot; ~ rnorm(1, mean = 0, sd = 1)
    ))
  
  #&gt; # A tibble: 15 × 2
  #&gt; # Rowwise: 
  #&gt;    letter   Proj
  #&gt;    &lt;chr&gt;   &lt;dbl&gt;
  #&gt;  1 A       9.82 
  #&gt;  2 A       7.72 
  #&gt;  3 A      12.9  
  #&gt;  4 A       7.81 
  #&gt;  5 A       6.44 
  #&gt;  6 B      10.4  
  #&gt;  7 B       3.14 
  #&gt;  8 B       1.48 
  #&gt;  9 B      28.7  
  #&gt; 10 B      11.0  
  #&gt; 11 C      -0.378
  #&gt; 12 C      -0.340
  #&gt; 13 C       1.81 
  #&gt; 14 C       1.03 
  #&gt; 15 C      -0.679
  </code></pre>
  <p><sup>Created on 2022-07-29 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v2.0.1)</sup></p>
  <p>What's going on here?</p>