我按照本指南: http://www.biostat.jhsph.edu/~rpeng/docs/interface.pdf.C接口與R
我想C語言創建copiled代碼中的R 使用它,所以我創造了我的hello.c文件:
#include <R.h>
void hello(int *n)
{
int i;
for(i=0; i < *n; i++) {
Rprintf("Hello, world!\n");
}
}
我把它保存在c:\ temp 完成之後,我必須編譯C代碼。
老實說,我沒有任何想法,我在做什麼,但我特林在cmd中窗口寫:
cd C:\Program Files\R\R-3.0.2\bin\
R CMD SHLIB c:\temp\hello.c
而我得到的錯誤:
cygwin warning: MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/i386/Makeconf Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/i386/Makeco nf CYGWIN environment variable option "nodosfilewarning" turns off this warning. Consult the user's guide for more details about POSIX paths: http://cygwin.com/cygwin-ug-net/using.html#using-pathnames make: * No rule to make target
c:\temp\hello.o', needed by
c:\temp\hello.dll '. Stop.
這應該創建一個文件名「hello.so」。所以我可以把它叫做R:
dyn.load("hello.so")
hello2 <- function(n) {
.C("hello", as.integer(n))
}
hello2(5)
但是我的命令並沒有創建hello.so文件。 也許我需要安裝另一個編譯器,但我無法在我使用的PC上安裝軟件。有沒有辦法做到這一點與Windows CMD?我的錯誤在哪裏?
您需要按照R的[附錄D:Windows工具集](http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset)安裝和管理手冊。 – 2014-09-01 16:56:00
相關問題在這裏:http://stackoverflow.com/questions/13987667/r-external-interface與其他一些資源 – 2014-09-01 19:54:19
我認爲'.C'即將消失。 Dirk在他的答案中提到了它http://stackoverflow.com/questions/23453373/function-c-argument-setup-fails-compilation。推薦'.Call'和'。外部'而不是 – 2014-09-01 20:44:07