从R将整个C++管道作为黑盒运行
Running entire C++ pipeline as blackbox from R
我有一个.cpp文件(我认为是一个类),我认为它是一个黑盒:它只需要一个特定格式的.txt文件作为输入,并写入另一个.txt文件作为输出。
如何在R中使用此代码?Rcpp
包似乎是可行的,但从浏览网页来看,我看到的所有答案/帖子都涉及从R调用单个C++函数(例如,使用// [[Rcpp::export]]
)。但就我而言,我对某个特定的功能不感兴趣。我只想把整个C++脚本作为一个黑盒来运行。。。
独立于R,使用C++编译器进行编译
g++ imtd.cpp -o imtd
生成一个可执行文件,然后创建一个R程序来生成输入文件edgelist.txt
,使用R shell
命令运行可执行文件并在中读取输出文件edgelist-out.txt
shell("imtd edgelist")
# read edgelist-out.txt into R
# - the first field of the first line contains the number of triangles
# - lines containing a comma have 3 fields separated by one or more punctuation characters
# - there are some class counts at the end which we recompute rather than read
L <- readLines("edgelist-out.txt")
no.of.triangles <- read.table(text = L, nrow = 1)[[1]]
# extract lines with a comma, replace punctuation with space & create 3 column data frame
DF <- read.table(text = gsub("[[:punct:]]", " ", grep(",", L, value = TRUE)))
# rather than read in the class counts compute them from DF
tab <- table(DF$V3) # table of class counts
你不需要Rcpp。如上所述,可以将imtd.cpp
文件视为只知道输入和输出文件格式的黑盒。
相关文章:
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 如何在MS Visual Studio 2019中运行QT UI
- 如何通过cpp程序运行shell脚本
- IPC使用多个管道和分支进程来运行Python程序
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- Gstreamer基本管道正在运行,但未显示在Windows7虚拟盒上
- 从R将整个C++管道作为黑盒运行
- 运行库沙盒
- 小猎骨黑闪光板载 USR0 LED C++,代码运行但 LED 不变
- 从沙盒应用程序运行clang编译器的任何可能方式
- 在沙盒中运行插件