[R] Help with interfacing C & R

Oleg Sklyar osklyar at ebi.ac.uk
Thu Feb 8 22:20:21 CET 2007


On Windows you need:
  - download and install Cygwin (cygwin.com) with default options,
    supposedly you install into c:\cygwin. Add path to
    c:\cygwin\bin;c:\cygwin\lib to your system PATH
  - download and unpack Rtools
    (http://www.murdoch-sutherland.com/Rtools/tools.zip)
    Assuming you have them in C:\Rtools, add c:\RTools\bin
    to your PATH _in front of_ cygwin
  - download and install MinGW, you will want to get MinGW-5.1.3.exe,
    which will download and install the rest. You will want to select
    at least gcc and make. Add the path to c:\MinGW\bin to your system
    PATH, right in front of Rtools
    (http://sourceforge.net/projects/mingw/)
  - download and install ActivePerl from (activestate.com), ensure path
    is added to your PATH

For help files:
  - get MS hhc, comes as part of htmlhelp.exe from here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=00535334-c8a6-452f-9aa0-d597d16580cc&DisplayLang=en
    this is Microsoft HTML Help Compiler, add path to it to your PATH
  - you might want to consider MikTex, dowload, install, add to path if
    you have a package and a help system a should be built

Be sure that when installing R you included sources for compilation! You 
might need to reinstall R. When this done, you can try executing R CMD 
SHLIB or R CMD build --binary if you have a package.

Please refer to "Writing R Extensions" (CRAN) for complete reference and 
to this guide for step-by-step description:

http://www.ebi.ac.uk/~osklyar/kb/CtoRinterfacingPrimer.pdf

Regards,
Oleg

--
Dr Oleg Sklyar | EBI-EMBL, Cambridge CB10 1SD, UK | +44-1223-494466


Tim Smith wrote:
> Hi all,
> 
> I was trying to set up an interface for using C functions in R. For this, my R file hello2.r is:
> 
> ---------------------------------------------------------------------------------
> 
> hello2 <- function(n) {
> .C("hello", as.integer(n))
> }
> 
> hello2(3)
> --------------------------------------------------------------------------------
> 
> and my hello.c file is:
> 
> ------------------------------------------------------------------------------
> #include <R.h>
> void hello(int *n)
> {
>     int i;
>     for(i=0; i < *n; i++) {
>     Rprintf("Hello, world!\n");
>     }
> }
> ---------------------------------------------------------------------------
> 
>>From my windows command line, I execute:
> 
>> R CMD SHLIB hello.c
> 
> but I get the error message:
> Error: syntax error in "R CMD". I am trying to look up information on the web page at:  http://cran.r-project.org/doc/manuals/R-exts.html#dyn_002eload-and-dyn_002eunload
> 
> As I understand it, I need to load some files, but I don't understand which commands I need to execute to compile & execute my 'hello world' code.
> 
> I am running R 2.4.0 on Windows XP machine.
> 
> Any help would be highly appreciated.
> 
> thanks!
> 
>  
> ---------------------------------
> Food fight? Enjoy some healthy debate
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list