[R] Help with interfacing C & R

Oleg Sklyar osklyar at ebi.ac.uk
Fri Feb 9 00:38:19 CET 2007


Try the following:

Let's assume you put your R and C code into: E:\MyProgram

I assume R is in E:\prg_files\R\R-2.4.1\bin. I also assume MinGW is 
present and ActivePerl is present. I also assume the following 
directories are present (and full of files): 
E:\prg_files\R\R-2.4.1\include; E:\prg_files\R\R-2.4.1\src\gnuwin32. If 
they are not present -- you probably need to reinstall R with 
development files.

Now click on Start in Windows, run "Run As..." or anything that allows 
to run programs by name, type in the dialog "cmd" and hit OK. This will 
start a black DOS box!
Type:

E: <Enter> it should prompt that you are in E: now
cd MyProgram <Enter> now you are in E:\MyProgram
R CMD SHLIB hello.c <Enter>

If this does not work, type in the same box:

echo %PATH% <Enter>

and send us the contents of this printout (PATH).

Oleg

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


Tim Smith wrote:
> Hi All,
> 
> Thanks so much for all the responses. I think I don't know enough about 
> R, and I don't know what other information would be required to diagnose 
> what I may be doing wrong.
> 
> I have installed all the software, and reinstalled R as per Olegs 
> earlier email. I have all programs installed on my E:\ partition (R on 
> it's own works fine from here). When I had executed the code:
> 
>> R CMD SHLIB hello.c
> 
> it was clicking on the 'Rterm.exe' (R for windows front end, at E:\prg_files\R\R-2.4.1\bin). I had put my hello.c and the hell.r file in the bin directory too.
> 
> So, my question is where should I put my files, and which "DOS box" do I have to use? I started cygwin and got a bash command window - what do I do from here?
> 
> Thanks again for all the help, and I do apologize if I'm not giving the 'right' information.
> 
> Tim
> 
> 
> 
> 
> 
> 
> 
> */Roland Rau <roland.rproject at gmail.com>/* wrote:
> 
>     Dear Oleg,
> 
>     to avoid any misunderstandings: My intention was not to offend you.
>     I just thought that the original poster's idea was to compile simply
>     some C-code and interface it from R.
> 
>     I am sorry if my previous email sounded impolite.
> 
>     Best,
>     Roland
> 
> 
>     On 2/8/07, *Oleg Sklyar* <osklyar at ebi.ac.uk
>     <mailto:osklyar at ebi.ac.uk>> wrote:
> 
>         Roland,
> 
>         Sure, this code also compiles on my Linux box straight away, it also
>         compiles on my Windows box -- because everything is _already_ set up
>         there. The question was not whether the code was wrong -- such a
>         "huge"
>         chunk of code could hardly be wrong and it was apparent it was
>         written
>         just to try if one can _at all_ compile something for R. The
>         question
>         was that something was missing to compile it and Tim did not specify
>         anything about his system except that it was Windows!
> 
>         One might not need Cygwin if the code is like Tim's, i.e. has no
>         configuration whatsoever, that is right, but one in any case
>         needs at
>         least MinGW (for gcc, visible in your output) and ActivePerl
>         (for R CMD)
>         and RTools and R includes (visible in your output). You do have them
>         installed, does Tim also have them installed? If one adds a simple
>         config file (it will rather not work with a full UNIX-like
>         configure)
>         then one might want to have Cygwin or MSYS as well.
> 
>         Tim, when you get all those, add paths to <smth>\bin and
>         <smth>\lib (as
>         there might be dlls and Windows searches for dlls in the PATH)
>         to your
>         PATH. This includes R! One requirement: MinGW must be added in
>         front of
>         Cygwin (for MinGW make) and RTools in front of both MinGW and Cygwin
>         (for all RTools to be used instead of those).
> 
>         And the pdf file pointed to in my previous post was exactly
>         written for
>         someone to start doing these things! It was written for Linux,
>         but the
>         only difference on Windows is that you need those tools I
>         mentioned above!
> 
>         Oleg
> 
>         --
>         Dr Oleg Sklyar | EBI-EMBL, Cambridge CB10 1SD, UK | +44-1223-494466
> 
> 
>         Roland Rau wrote:
>          > Hi,
>          >
>          > On 2/8/07, *Oleg Sklyar* <osklyar at ebi.ac.uk
>         <mailto:osklyar at ebi.ac.uk> <mailto:osklyar at ebi.ac.uk
>         <mailto:osklyar at ebi.ac.uk>>>
>          > wrote:
>          >
>          >     On Windows you need:
>          >       - download and install Cygwin (cygwin.com
>         <http://cygwin.com> <http://cygwin.com>)
>          >     with default options,
>          >         supposedly you install into c:\cygwin. Add path to
>          >         c:\cygwin\bin;c:\cygwin\lib to your system PATH
>          >
>          >
>          > No. You don't need Cygwin. I don't have it and I can compile
>         Tim's code
>          > without any problem.
>          > Please see bottom of my message for which I used Tim's code
>         without any
>          > modification.
>          >
>          > My assumption is rather that the path is not set correctly so
>         he can
>          > call R from the command line.
>          > Maybe you could check, Tim, if you can start Rterm.exe or
>         Rgui.exe from
>          > the command line.
>          > If not, this should be the first thing to fix.
>          >
>          >
>          >
>          >
>          >     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
>         <http://www.microsoft.com/downloads/details.aspx?FamilyID=00535334-c8a6-452f-9aa0-d597d16580cc&DisplayLang=en>
>          >    
>         <http://www.microsoft.com/downloads/details.aspx?FamilyID=00535334-c8a6-452f-9aa0-d597d16580cc&DisplayLang=en
>         <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
>          >
>          > Yes, as you write for the help files. But I think it is not
>         necessary if
>          > someone wants to make his/her first steps to interface to C
>         from R.
>          >
>          >
>          > Best,
>          > Roland
>          >
>          > P.S.
>          > Here is the transcript of my shell session in emacs using
>         Tim's code:
>          >
>          > Microsoft Windows XP [Version 5.1.2600]
>          > (C) Copyright 1985-2001 Microsoft Corp.
>          >
>          > c:\deletefolder\Rsandbox>R CMD SHLIB hello.c
>          > R CMD SHLIB hello.c
>          > making hello.d from hello.c
>          > gcc   -IC:/rolandprogs/R- 2.3.1/include -Wall -O2   -c
>         hello.c -o hello.o
>          > gcc  -shared -s  -o hello.dll hello.def hello.o
>          > -LC:/rolandprogs/R- 2.3.1/bin   -lR
>          >
>          > c:\deletefolder\Rsandbox>Rterm --no-save
>          > Rterm --no-save
>          >
>          > R : Copyright 2006, The R Foundation for Statistical Computing
>          > Version 2.3.1 (2006-06-01)
>          > ISBN 3-900051-07-0
>          >
>          > R is free software and comes with ABSOLUTELY NO WARRANTY.
>          > You are welcome to redistribute it under certain conditions.
>          > Type 'license()' or 'licence()' for distribution details.
>          >
>          > R is a collaborative project with many contributors.
>          > Type 'contributors()' for more information and
>          > 'citation()' on how to cite R or R packages in publications.
>          >
>          > Type 'demo()' for some demos, 'help()' for on-line help, or
>          > 'help.start()' for an HTML browser interface to help.
>          > Type 'q()' to quit R.
>          >
>          >  > source(" hello2.r")
>          > source("hello2.r")
>          >  > dyn.load("hello")
>          > dyn.load("hello")
>          >  > hello2(3)
>          > hello2(3)
>          > Hello, world!
>          > Hello, world!
>          > Hello, world!
>          > [[1]]
>          > [1] 3
>          >
>          >  >
> 
> 
> 
> ------------------------------------------------------------------------
> TV dinner still cooling?
> Check out "Tonight's Picks" 
> <http://us.rd.yahoo.com/evt=49979/*http://tv.yahoo.com/> on Yahoo! TV.



More information about the R-help mailing list