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