本文介绍了 - [R从C - 尽可能简单的Helloworld的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是用于开始第r间preTER,传递一个小的前pression(例如,2 + 2),并得到了结果的最简单的可能的C函数?我想使用MinGW编译在Windows上。What is the simplest possible C function for starting the R interpreter, passing in a small expression (eg, 2+2), and getting out the result? I'm trying to compile with MingW on Windows.推荐答案您想从C调用R'在该 8.1节看写R附加手册。你也应该看看进入测试目录(下载源代码包解压缩,你就会有测试目录)。类似的问题是previously问及R-帮助和的这里是例子:Look at section 8.1 in the Writing R Extensions manual. You should also look into the "tests" directory (download the source package extract it and you'll have the tests directory). A similar question was previously asked on R-Help and here was the example:#include <Rinternals.h>#include <Rembedded.h>SEXP hello() { return mkString("Hello, world!\n");}int main(int argc, char **argv) { SEXP x; Rf_initEmbeddedR(argc, argv); x = hello(); return x == NULL; /* i.e. 0 on success */}从R手动的简单的例子是,像这样:The simple example from the R manual is like so: #include <Rembedded.h> int main(int ac, char **av) { /* do some setup */ Rf_initEmbeddedR(argc, argv); /* do some more setup */ /* submit some code to R, which is done interactively via run_Rmainloop(); A possible substitute for a pseudo-console is R_ReplDLLinit(); while(R_ReplDLLdo1() > 0) { add user actions here if desired } */ Rf_endEmbeddedR(0); /* final tidying up after R is shutdown */ return 0; }顺便说一句,你可能要考虑使用的 Rinside 来代替:德克提供的一个很好的Hello World的例子中的项目主页。Incidentally, you might want to consider using Rinside instead: Dirk provides a nice "hello world" example on the project homepage.在你感兴趣的调用由R C,这是我原来的答复:In you're interested in calling C from R, here's my original answer:这是不完全的hello world,但这里有一些很好的资源:This isn't exactly "hello world", but here are some good resources:周杰伦艾默生最近给在纽约的用户群R上封装发展的谈话,他提供了使用C从内部R的一些非常好的例子看一看的从他的网站这次讨论中,开始第9页的纸张所有相关的源$ C $ C是在这里: http://www.stat.yale.edu/~jay/Rmeetup/MyToolkitWithC/ 。 在哈佛受戈皮·哥斯瓦米在2005年讲授课程: C-C ++ - R(统计)。这包括大量的示例和源$ C $ C。Jay Emerson recently gave a talk on R package development at the New York useR group, and he provided some very nice examples of using C from within R. Have a look at the paper from this discussion on his website, starting on page 9. All the related source code is here: http://www.stat.yale.edu/~jay/Rmeetup/MyToolkitWithC/.The course taught at Harvard by Gopi Goswami in 2005: C-C++-R (in Statistics). This includes extensive examples and source code. 这篇关于 - [R从C - 尽可能简单的Helloworld的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 15:52