title: Data type conversion error in using Rcpp
body: <p>I am learning Rcpp and write the following two functions. The second function simply computes sum(log_gamma(x)) - log_gamma(sum(x)) where x is a vector.</p>
  
  <p>Three data type conversion errors are returned, all of which I am not able to resolve. Can someone help me correct the codes? Thanks.</p>
  
  <pre><code>file330c72cf6532.cpp:8:37: error: cannot convert 'Rcpp::sugar::Vectorized&lt;Rf_lgammafn, true, Rcpp::Vector&lt;14, Rcpp::PreserveStorage&gt; &gt;' to 'SEXP' in initialization
               SEXP lgamma_x = lgamma(x);
                                       ^
  file330c72cf6532.cpp:10:45: error: cannot convert 'SEXP' to 'double' in initialization
               double up = sum_cpp(lgamma_x_vec);
                                               ^
  file330c72cf6532.cpp:11:44: error: cannot convert 'Rcpp::sugar::Vectorized&lt;Rf_lgammafn, true, Rcpp::Vector&lt;14, Rcpp::PreserveStorage&gt; &gt;' to 'double' in initialization
               double down = lgamma(sum_cpp(x));
                                              ^ 
  
  cppFunction(
    'double sum_cpp(NumericVector x){
      double tmp = 0;
      int n = x.size();
      for(int j = 0; j&lt;n; j++){
        tmp = tmp + x[j];
      }
      return tmp;
    }')
  
  cppFunction('double LogB_cpp(NumericVector x){
              Function sum_cpp( "sum_cpp" ) ;
              SEXP lgamma_x = lgamma(x);
              NumericVector lgamma_x_vec(lgamma_x);
              double up = sum_cpp(lgamma_x_vec);
              double down = lgamma(sum_cpp(x));
              return up - down;}')
  </code></pre>