如何运行的R积成C / C ++? [英] how to run plot of R into C/C++?

查看:175
本文介绍了如何运行的R积成C / C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何用C执行R指令,而无需使用R附加,是这样的:

  INT的main(){   系统(R G<  - 图(C(0,1,0,4,0,9,1,7,1,9,2,9,2,3,2,5,3,6,3,9 ,4,5,4,8,5,8,6,7,6,8,7,8),N = 10,DIR = FALSE)
    图(七))    返回(0)
}


解决方案

您可以使用 - [R系统()调用,你必须跑,但你不能像在命令行上粘贴R里面的函数。

你可以做的是在R code写入文件和称它为系统(R CMD批foo.R) - 微创:

 的main(){系统(R CMD批test.R);}

现在,在默认情况下从研发CMD批的图形输出到PDF文件,所以您需要打开一个图形窗口,使脚本暂停,如果你想看到它。

当然您test.R文件可能被你的C code写的运行它之前,你可以把它放在一个临时目录或东西。

How do I execute a R command in C, without using R extensions, something like:

int main() {

   system("R g<- graph(c(0,1,0,4,0,9,1,7,1,9,2,9,2,3,2,5,3,6,3,9,4,5,4,8,5,8,6,7,6,8,7,8),n=10,dir=FALSE)
    plot(g)")

    return(0)
}

解决方案

You can run R using the system() call as you have, but you can't stick R functions on the command line like that.

What you can do is to write the R code to a file and call it with system("R CMD BATCH foo.R") - minimally:

main(){system("R CMD BATCH test.R");}

Now, by default the output graphics from R CMD BATCH go to a PDF file, so you need to open a graphics window and make the script pause if you want to see it.

Of course your test.R file could be written by your C code before it runs it, and you could keep it in a temporary directory or something.

这篇关于如何运行的R积成C / C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆