I'm following this guide: http://www.biostat.jhsph.edu/~rpeng/docs/interface.pdf
I want to create code copiled in C to use it in R So I created my hello.c file:
#include <R.h>
void hello(int *n)
{
int i;
for(i=0; i < *n; i++) {
Rprintf("Hello, world!\n");
}
}
And I saved it in c:\temp Having done that, I must then compile the C code.
I honestly don't have any idea what I'm doing but I'm tring to write in windows cmd:
cd C:\Program Files\R\R-3.0.2\bin\
R CMD SHLIB c:\temp\hello.c
And I get the error:
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.
This should create a file names "hello.so". So I can call it in R with:
dyn.load("hello.so")
hello2 <- function(n) {
.C("hello", as.integer(n))
}
hello2(5)
But my command doesn't create the hello.so file. Maybe I need to install another compiler, but I can't install software in the PC that I'm using. Is there a way to do it with the windows cmd? Where is my mistake?
.C
is going away soon. Dirk mentions it in his answer here stackoverflow.com/questions/23453373/…. Recommending.Call
and.External
instead – Rich Scriven.C()
is limited whereas.Call()
allows full objects access. – Dirk Eddelbuettel