如何直接从 R 库运行 igraph C 库函数?

问题描述 投票:0回答:1

我尝试了

make_tree()
的副本:

library(igraph)
myfun <-
function (n, children = 2, mode = c("out", "in", "undirected")) 
{
    mode <- igraph.match.arg(mode)
    mode1 <- switch(mode, out = 0, `in` = 1, undirected = 2)
    on.exit(.Call(R_igraph_finalizer))
    res <- .Call(R_igraph_kary_tree, as.numeric(n), as.numeric(children), 
        as.numeric(mode1))
    if (igraph_opt("add.params")) {
        res$name <- "Tree"
        res$children <- children
        res$mode <- mode
    }
    res
}
myfun(n=3, children=2)

这给出:

Error in igraph.match.arg(mode) : 
  could not find function "igraph.match.arg"
  • Q1:如何使
    igraph.match.arg()
    .Call()
    在R库中可用?
  • Q2:如何概述 igraph C 库中的所有可用函数。
    A2:unclass(lsf.str(envir = asNamespace("igraph"), all = TRUE))
r shared-libraries igraph
1个回答
0
投票

您需要告诉 R 从哪里获取不在搜索路径上的对象(例如,因为它们不是由包导出的)。

myfun <-
  function (n, children = 2, mode = c("out", "in", "undirected")) 
  {
    mode <- igraph:::igraph.match.arg(mode)
    mode1 <- switch(mode, out = 0, `in` = 1, undirected = 2)
    on.exit(.Call(igraph:::R_igraph_finalizer))
    res <- .Call(igraph:::R_igraph_tree, as.numeric(n), as.numeric(children), 
                 as.numeric(mode1))
    if (igraph:::igraph_opt("add.params")) {
      res$name <- "Tree"
      res$children <- children
      res$mode <- mode
    }
    res
  }
myfun(n=3, children=2)
#works

R_igraph_kary_tree
不是来自 igraph 包。

© www.soinside.com 2019 - 2024. All rights reserved.