[Rcpp-devel] Calling igraph from within Rcpp
Pavankumar Gurazada
efpm04015 at iiml.ac.in
Thu Mar 15 13:29:59 CET 2018
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:
#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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180315/19b026fc/attachment-0001.html>
More information about the Rcpp-devel
mailing list