简体   繁体   English

Rcpp:使用 igraph 函数时出现明显错误

[英]Rcpp: Obvious error when using igraph functions


I'm quite new to Rcpp.我对 Rcpp 很陌生。 Sorry If I'm missing something obvious.抱歉,如果我遗漏了一些明显的东西。
but when I try to use an igraph function in Rcpp I face the following obvious error on the left:但是当我尝试在 Rcpp 中使用 igraph function 时,我在左侧遇到以下明显错误:
"Cannot initialize a Variable of type 'RCPP:Environment' (aka,'int') with an lvalue of type 'const char[15]' “无法使用“const char[15]”类型的左值初始化“RCPP:Environment”类型的变量(又名“int”)
Here is the code这是代码

#include <Rcpp.h>
// [[Rcpp::plugins(cpp11)]]
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector insideOfCommEdgeIdsCpp(CharacterVector g, CharacterVector v) {
Environment igraph("package:igraph");
Function game_er = igraph["erdos.renyi.game"];
Function get_adjacency = igraph["get.adjacency"];
}

A few small errors in your file:您的文件中有一些小错误:

  • declared as NumericVector but nothing is returned声明为NumericVector但没有返回任何内容
  • Environment igraph not set up correctly. Environment igraph未正确设置。

A corrected version is below.修正版如下。 And it it worth repeating this: Any R functions called from C++ are still R functions that run at the speed of R functions. And it it worth repeating this: Any R functions called from C++ are still R functions that run at the speed of R functions.

Corrected code更正的代码

#include <Rcpp.h>
// [[Rcpp::plugins(cpp11)]]
using namespace Rcpp;
// [[Rcpp::export]]
void insideOfCommEdgeIdsCpp(CharacterVector g, CharacterVector v) {
  Environment igraph = Environment("package:igraph");
  Function game_er = igraph["erdos.renyi.game"];
  Function get_adjacency = igraph["get.adjacency"];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM