title: Error when calling Rcpp function from Tableau. How to interpret and debug Rserve logs?
body: <p>I'm having a lot of trouble connecting an R function I wrote to Tableau. The function relies on Rcpp.</p>
  
  <p>In R, if I call <code>prob_1_beats_2(1, 2, 3, 4)</code> it works just fine. However, when I try to connect to Tableau using Rserve, I get this error:</p>
  
  <p><code>Error in eval(expr, envir, enclos) : expecting a single value</code></p>
  
  <p>which I cannot seem to trace down. I tried running Rserve in debug mode but to no avail. I'm unsure how to interpret these results. It would be nice to traceback exactly what is being called in R.</p>
  
  <p>Gist of debug logs: <a href="https://gist.github.com/FrankPortman/f5cfe32596fd47080286" rel="nofollow">https://gist.github.com/FrankPortman/f5cfe32596fd47080286</a></p>
  
  <pre><code>prob_1_beats_2 &lt;- function(alpha_1, beta_1, alpha_2, beta_2, percent_lift = 0) {
  
    if(alpha_1 / beta_1 &lt; alpha_2 / beta_2) {
  
      t1 &lt;- alpha_2
      t2 &lt;- beta_2
  
      alpha_2 &lt;- alpha_1
      beta_2 &lt;- beta_1
  
      alpha_1 &lt;- t1
      beta_1 &lt;- t2
  
    }
  
    alt_count(alpha_1, beta_1, alpha_2, beta_2)
  
  }
  </code></pre>
  
  <p>And here is the Rcpp function:</p>
  
  <pre><code>double alt_count(double alpha_1, double beta_1, double alpha_2, double beta_2) {
  
    double total = 0;
  
    for(int i = 0; i &lt; alpha_1; i++) {
  
      total += exp(i * log(beta_1) + alpha_2 * log(beta_2) - (i + alpha_2) * log(beta_1 + beta_2) - log(i + alpha_2) - lbeta(i + 1, alpha_2));
  
    }
  
    return total;
  
  }
  </code></pre>
  
  <p>As you can see:</p>
  
  <pre><code>&gt; prob_1_beats_2(1, 2, 3, 4)
  [1] 0.7037037
  </code></pre>
  
  <p>Finally, the Tableau call I am using:</p>
  
  <pre><code>SCRIPT_REAL("library(mypackage);prob_1_beats_2(.arg1, .arg2, .arg3, .arg4)", 1.0, 2.0, 3.0, 4.0)
  </code></pre>
  
  <p>Note that </p>
  
  <pre><code>SCRIPT_REAL("library(mypackage);prob_1_beats_2(1, 2, 3, 4)", 1.0, 2.0, 3.0, 4.0)
  </code></pre>
  
  <p>does return 0.7037037. The real Tableau call I will be using will not use constant values of 1:4 but I am trying this for debugging purposes.</p>