从R调用Saucy(可执行的C程序)

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

我有一个可执行的C程序(./saucy),我从运行Saucy的makefile获得(源代码here

跑./saucy graphfile

得到我作为输出

(0 2)(3 4) (0 1)(2 4)

如何从R脚本中调用它?在读完this post之后,我正在挠头。

c r
1个回答
3
投票

我只将saucy命令行包装到一个同名的R函数中,并且只在macOS和Ubuntu上测试它,但它跟踪你的示例输出。

通过“包裹”我的意思是它不会调用二进制文件,它是一个从R调用的C函数。剥离cmdline cruft并不困难。作者做了相当不错的工作。

devtools::install_github("hrbrmstr/saucy")

library(saucy)

第一个示例文件:

graph1 <- saucy::saucy(system.file("extdata", "graphfile", package="saucy"))

graph1
## (0 2)(3 4)
## (0 1)(2 4)
## 
##           input_file: graphfile
##             vertices: 5
##                edges: 5
##      group_size_base: 1
##       group_size_exp: 1
##               levels: 3
##                nodes: 7
##           generators: 2
##        total_support: 8
##      average_support: 4
##  nodes_per_generator: 3.5
##            bad_nodes: 0

str(graph1)
## List of 13
##  $ input_file         : chr "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/saucy/extdata/graphfile"
##  $ vertices           : int 5
##  $ edges              : int 5
##  $ group_size_base    : num 1
##  $ group_size_exp     : int 1
##  $ levels             : int 3
##  $ nodes              : int 7
##  $ generators         : int 2
##  $ total_support      : int 8
##  $ average_support    : num 4
##  $ nodes_per_generator: num 3.5
##  $ bad_nodes          : int 0
##  $ printed_output     : chr [1:2] "(0 2)(3 4)" "(0 1)(2 4)"
##  - attr(*, "class")= chr [1:2] "saucy" "list"

第二个示例文件:

graph2 <- saucy::saucy(system.file("extdata", "graphfile2", package="saucy"))

graph2
## (3 5)
## (3 6)(4 5)
## (0 1)
## (0 2)
## 
##           input_file: graphfile2
##             vertices: 7
##                edges: 7
##      group_size_base: 4.8
##       group_size_exp: 1
##               levels: 5
##                nodes: 13
##           generators: 4
##        total_support: 10
##      average_support: 2.5
##  nodes_per_generator: 3.25
##            bad_nodes: 0


str(graph2)
## List of 13
##  $ input_file         : chr "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/saucy/extdata/graphfile2"
##  $ vertices           : int 7
##  $ edges              : int 7
##  $ group_size_base    : num 4.8
##  $ group_size_exp     : int 1
##  $ levels             : int 5
##  $ nodes              : int 13
##  $ generators         : int 4
##  $ total_support      : int 10
##  $ average_support    : num 2.5
##  $ nodes_per_generator: num 3.25
##  $ bad_nodes          : int 0
##  $ printed_output     : chr [1:4] "(3 5)" "(3 6)(4 5)" "(0 1)" "(0 2)"
##  - attr(*, "class")= chr [1:2] "saucy" "list"

shatter也包裹着。

我也可以在某些时候采用真正的图形结构与读取序列化结构,但我不知道这个库/工具有多受欢迎,因此无法提交时间范围。

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