Compiling RInside programs on Windows [duplicate]

南楼画角 提交于 2020-01-11 13:02:08

问题


Possible Duplicate:
Problem with compiling RInside examples under Windows

On Windows XP:

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
> 

I attempted to compile the simplest program written by Dirk:

#include <RInside.h>                    // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);              // create an embedded R instance

    R["txt"] = "Hello, world!\n";   // assign a char* (string) to 'txt'

    R.parseEvalQ("cat(txt)");           // eval the init string, ignoring any returns

    exit(0);
}

The environment variable PATH in all contains this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\R\batchfiles_0.6-6;C:\R\Rtools\bin;C:\R\Rtools\MinGW\bin;C:\Program Files\GnuWin32;C:\"Program Files"\R\R-2.15.1\;

I copied this Makefile from a existing R example of RInside in Windows XP.

## -*- mode: make; 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 :=       C:\"Program Files"\R\R-2.15.1\

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)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=      -Wl,-rpath,$(R_HOME)/lib

## 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)
LDLIBS :=       $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

all:            $(programs)
            @test -x /usr/bin/strip && strip $^

run:            $(programs)
            @for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done

clean:
            rm -vf $(programs)
            rm -vrf *.dSYM

runAll:
            for p in $(programs); do echo "Running $$p"; ./$$p; done

This is my R folder in C drive:

I saw this thread but I don't have anything like site-library in the R folder.

I changed the R_HOME to C:\"Program Files"\R\R-2.15.1, that resulted in the following errors:


回答1:


It fails because you installed R in C:\Program Files\R even though the FAQ for R on Windows tells you not to install R in a path with spaces. See "Question 2.2: How do I install R for Windows":

If you want to be able to build packages from sources, we recommend that you choose an installation path not containing spaces.

The Rcpp / RInside documentaion repeats that recommendation. Do not install R in a path with spaces. If you must, you have to fix the Makefile to avoid the path expansion from breaking.




回答2:


Your path are totally wrong for me: why you use C:\R\Rtools\bin as R_HOME if your R main path is simply C:\R ? If your R folder is what you've shown in the screenshot, BTW, also your classpath is totally wrong!



来源:https://stackoverflow.com/questions/12928863/compiling-rinside-programs-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!