Yes, apologies for getting too eager! I should have waited.<br><br>On Thursday, March 15, 2018, Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 15 March 2018 at 16:29, Pavankumar Gurazada wrote:<br>
|  As a part of utilizing network data drawn at random before further<br>
| processing, I am trying to call a couple of functions from the igraph package<br>
| at the beginning of each iteration. The code I use is as follows:<br>
<br>
This is a cross-posted (which we discourage) over at StackOverflow at where I<br>
saw it first and already answered it:<br>
<br>
<a href="https://stackoverflow.com/questions/49299368/calling-igraph-from-within-rcpp" target="_blank">https://stackoverflow.com/<wbr>questions/49299368/calling-<wbr>igraph-from-within-rcpp</a><br>
<br>
In short, needs these two lines (or equivalent) in the middle:<br>
<br>
  SEXP g = game_er(Named("n", n), Named("p", p));<br>
<br>
  S4 A_m = get_adjacency(Named("g", g));<br>
<br>
<br>
Dirk<br>
<br>
<br>
<br>
| #define ARMA_64BIT_WORD#include <RcppArmadillo.h><br>
| // [[Rcpp::depends(RcppArmadillo)<wbr>]]// [[Rcpp::plugins(cpp11)]]<br>
| using namespace Rcpp;<br>
|<br>
| using arma::sp_mat;<br>
| // [[Rcpp::export]]<br>
| sp_mat adj_mat(int n, double p) {<br>
|<br>
|   Environment igraph("package:igraph");<br>
|   Function game_er = igraph["erdos.renyi.game"];<br>
|   Function get_adjacency = igraph["get.adjacency"];<br>
|<br>
|   List g = game_er(Named("n", n), Named("p", p));<br>
|<br>
|   NumericMatrix A_m = get_adjacency(Named("g", g));<br>
|<br>
|   sp_mat A = as<sp_mat>(A_m);<br>
|<br>
|   return A;}<br>
|<br>
|<br>
| /*** R<br>
| set.seed(20130810)<br>
| library(igraph)<br>
|<br>
| adj_mat(100, 0.5)*/<br>
|<br>
|<br>
|<br>
| So, while the C++ compiles without warnings, the following error is thrown:<br>
|<br>
| > sourceCpp("Hooking-R-in-cpp.<wbr>cpp")<br>
| > set.seed(20130810)<br>
| > library(igraph)<br>
| > adj_mat(100, 0.5)<br>
| Error in adj_mat(100, 0.5) :<br>
|   Not compatible with requested type: [type=S4; target=double].<br>
|<br>
| >From the error it looks like I am passing a S4 class to a double? Where is<br>
| the error?<br>
| ______________________________<wbr>_________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</blockquote>