8

I am trying to setup RInside at work where we are forced to use a Windows environment.

I have installed RTools and downloaded an RInside binary from CRAN.

My R installation resides in c:\R\R-2.12.2 so no problems with folders with spaces.

I have installed the Rcpp and RInside packages in R.

I execute the following makefile Makefile.win included in the downloaded RInside binary

## -*- mode: makefile; tab-width: 8; -*-
##
## Simple Makefile
##
## TODO:
##  proper configure for non-Debian file locations,   [ Done ]
##  allow RHOME to be set for non-default R etc

## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
R_HOME :=       'cygdrive/c/R/R-2.12.2'

sources :=      $(wildcard *.cpp)
programs :=         $(sources:.cpp=)

## include headers and libraries for R
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## include headers and libraries for Rcpp interface classes
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --    slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell     $(R_HOME)/bin/R     CMD config CXXFLAGS)
LDFLAGS =       -s
LDLIBS :=       $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RINSIDELIBS) $(RCPPLIBS) 
CC :=           $(shell $(R_HOME)/bin/R CMD config CXX)

all :           $(programs)

clean:
        rm -vf $(programs)

with the command

make -f Makefile.win

to try an build the standard examples included

However, I get the following error:

C:\RInside_0.2.3\RInside\examples\standard>make -f Makefile.win
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
cygdrive/c/R/R-2.12.2/bin/R: not found
cygdrive/c/R/R-2.12.2/bin/R: not found
cygdrive/c/R/R-2.12.2/bin/R: not found
cygdrive/c/R/R-2.12.2/bin/R: not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
make: cygdrive/c/R/R-2.12.2/bin/R: Command not found
Wall  -s  rinside_callbacks0.cpp        -o rinside_callbacks0
make: Wall: Command not found
make: [rinside_callbacks0] Error 127 (ignored)
Wall  -s  rinside_module_sample0.cpp        -o rinside_module_sample0
make: Wall: Command not found
make: [rinside_module_sample0] Error 127 (ignored)
Wall  -s  rinside_sample0.cpp        -o rinside_sample0
make: Wall: Command not found
make: [rinside_sample0] Error 127 (ignored)
Wall  -s  rinside_sample1.cpp        -o rinside_sample1
make: Wall: Command not found
make: [rinside_sample1] Error 127 (ignored)
Wall  -s  rinside_sample2.cpp        -o rinside_sample2
make: Wall: Command not found
make: [rinside_sample2] Error 127 (ignored)
Wall  -s  rinside_sample3.cpp        -o rinside_sample3
make: Wall: Command not found
make: [rinside_sample3] Error 127 (ignored)
Wall  -s  rinside_sample4.cpp        -o rinside_sample4
make: Wall: Command not found
make: [rinside_sample4] Error 127 (ignored)
Wall  -s  rinside_sample5.cpp        -o rinside_sample5
make: Wall: Command not found
make: [rinside_sample5] Error 127 (ignored)
Wall  -s  rinside_sample6.cpp        -o rinside_sample6
make: Wall: Command not found
make: [rinside_sample6] Error 127 (ignored)
Wall  -s  rinside_sample7.cpp        -o rinside_sample7
make: Wall: Command not found
make: [rinside_sample7] Error 127 (ignored)
Wall  -s  rinside_sample8.cpp        -o rinside_sample8
make: Wall: Command not found
make: [rinside_sample8] Error 127 (ignored)
Wall  -s  rinside_sample9.cpp        -o rinside_sample9
make: Wall: Command not found
make: [rinside_sample9] Error 127 (ignored)
Wall  -s  rinside_test0.cpp        -o rinside_test0
make: Wall: Command not found
make: [rinside_test0] Error 127 (ignored)
Wall  -s  rinside_test1.cpp        -o rinside_test1
make: Wall: Command not found
make: [rinside_test1] Error 127 (ignored)

I have tried with different paths for R_HOME but I question my ability to having found the right one. I am new to makefiles, so the error output is not of much help.

Hope somebody has some valuable insight to share!

Thanks in advance,

Christian

Christian Bøhlke
  • 779
  • 1
  • 7
  • 18
  • 4
    There's no such thing as R-2.1.2. Even if there were, it would be ~6 years old. – Joshua Ulrich Apr 13 '11 at 13:53
  • Nice catch. Also probably want a leading '/' for something like '/cygdrive/c/R/R-2.12.2'. Mixing Cygwin and MinGW has given me headaches too so maybe cmd.exe is best. Oh Windows.... – Dirk Eddelbuettel Apr 13 '11 at 13:58
  • @Joshua Ulrich @Dirk Eddelbuettel Having corrected both I am now able to compile! However, now it says that is not able to find the Rcpp and RInside packages which I specifically have installed. Will dive into that tomorrow! – Christian Bøhlke Apr 13 '11 at 14:07
  • That would be your local R use as the Makefile asks R to tell it where Rcpp and RInside, and *R* does not know. – Dirk Eddelbuettel Apr 13 '11 at 14:33

3 Answers3

6

You seem to have two distinct problems here:

  1. Your $PATH is probably off, or as Josh had hinted, your $R_HOME assignment is wrong. If make is indeed the binary from Rtools, and the paths you assign are correct, then the builds succeed. That is the general rule for building R packages on Windows: Follow the manual very diligently and it will work.

  2. RInside is broken on Windows, sorry. It will build, and you will get segfaults. Romain and I clearly state so in the documentation.

As Romain and I work almost exclusively on OS X and Linux, respectively, we would appreciate debugging help. It should be doable, but it probably requires some serious willingness to learn about R internals as something in the memory subsystem goes belly-up. Which it clearly does not on OSs with an X in their name.

Updated on 08 Dec 2011: RInside 0.2.5, on CRAN as of today, restores the Windows functionality--using the fix James notes in the other comment.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
6

I have a similar setup at work, so I gave this a shot. I'm able to build the examples after I specify R_LIBS_SITE. Note that it must be a Windows path, not a Cygwin path!

export R_LIBS_SITE=c:/R/site-library
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • I tend to say that in my ~/.Renvironment. The Makefile assumes that R knows about its packages. We must be able to query Rcpp and RInside about theirs paths. But if you have a good suggestion, send me a two-liner we could add to Makefile.win. – Dirk Eddelbuettel Apr 13 '11 at 14:35
  • @Dirk: I do too... on Linux. ;-) I have it specified in `R_HOME/etc/Rcmd_environ`, but it doesn't get picked up. It works if I export it from the shell though. – Joshua Ulrich Apr 13 '11 at 14:40
  • Well from memory, there is also Renviron.site and there always is ~/.R* as I wrote; else see help(Startup) – Dirk Eddelbuettel Apr 13 '11 at 14:50
  • 1
    Setting .Library.site <- file.path("C:/R/R-2.12.2/library") in my RProfile.site file was the medicine! Thanks a lot for helping out! Hope to see some of you at the upcoming RInFinance conference in Chicago! – Christian Bøhlke Apr 14 '11 at 09:35
4

I spent a little time today looking at the bug with the windows version of RInside. I believe that I have discovered the bug which is as follows:

In RInside::initialize(……) the structRStart structure is populated however this now requires extra fields to be populated in the case of windows as shown in Rf_initEmbeddedR() from R\src\gnuwin32\embedded.c.

Rp->rhome = RHome;
Rp->home = getRUser();
Rp->CharacterMode = LinkDLL;
Rp->ReadConsole = myReadConsole;
Rp->WriteConsole = myWriteConsole;
Rp->CallBack = myCallBack;
Rp->ShowMessage = askok;
Rp->YesNoCancel = askyesnocancel;
Rp->Busy = myBusy;

Equivalent assignments will be necessary in RInside.cpp in order to provide valid callbacks.

John Conde
  • 217,595
  • 99
  • 455
  • 496
James Bates
  • 151
  • 2
  • James kindly reported this to me in private email, and it looks promising. I don't have access to a Windows machine at this moment, if someone wants to test this please get in touch as I sent James a few follow-up email---but I reckon he called it a night. The relevant strucute is defined in RStartup.h with the fields shown here `#ifdef`-ed in on Windows. – Dirk Eddelbuettel Nov 28 '11 at 02:50