Home Ask Login Register

Developers Planet

Your answer is one click away!

Fatima Batool February 2016

Linking C and R in Windows

I am trying to Link R and C in windows while following the instructions on this web page


I have R, RTOOLS and TurboC4 all in separate folders in C drive. My system is 64bits but I have tried it on both 32 and 64 bit R.

I have written the following code in C

#include <R.h>

void hello(int *n)
 { int i;
    for(i=0; i<=*n; i++){
     Rprintf("hello, world!this is hell though I'm enjoying it\n");

and saved with name WORLD.C on separate file the path to which is C:\TurboC4\TC\BIN

I have also written the following R code

hello2 <- function(n) {
.C("hello", as.integer(n))


and save it with name WORLD.R.

Now I have to prepare my window. I have downloaded RTools33.exe from here https://cran.r-project.org/bin/windows/Rtools/

and set the environment variables manually through this command

PATH=c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;c:\Program Files\R\R-3.2.2\bin\i386; 

Then Reinstalled system

Before calling the C code in R I have to compile the C code in cmd. I write the following command to change the directory where WORLD.C is saved

cd C:\Users\TurboC4\TC\BIN

which is successful but when I try to compile


I get the following error. " 'R' is not recognized as internal or external command, operable ". I have also tried to compile WORLD.C in C and got these two errors. "Unable to open #include R.h>" and "function Rprintf should have a prototype".

Setting Environment is a Problem I think this is where I am facing problem. I have ch


Fatima Batool February 2016

This problem is now solved. There was just a minor mistake of defining the environment variable. The correct definition is as follows.

c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;c:\Program Files\R\R-3.2.2\bin\i386; 

Post Status

Asked in February 2016
Viewed 3,156 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life