在Windows系统下编译RInside示例的问题

8
我正在尝试在工作中设置RInside,我们被迫使用Windows环境。
我已经安装了RTools并从CRAN下载了一个RInside二进制文件
我的R安装位于c:\R\R-2.12.2,因此不会出现带空格的文件夹问题。
我已经在R中安装了RcppRInside软件包。
我执行了下载的RInside二进制文件中包含的Makefile.win
## -*- 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)

使用该命令

make -f Makefile.win

我想尝试构建包含在标准示例中的内容。

但是,我遇到了以下错误:

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)

我已经尝试了不同的路径来设置R_HOME,但我怀疑自己是否找到了正确的路径。我对makefile还很陌生,因此错误输出对我帮助不大。

希望有人能分享一些有价值的见解!

提前感谢,

Christian


4
“R-2.1.2”这个版本号是不存在的。即使存在,它也至少已经有六年历史了。 - Joshua Ulrich
不错的发现。对于像“/cygdrive/c/R/R-2.12.2”这样的东西,也可能需要一个前导斜杠。混合使用Cygwin和MinGW也让我头疼,所以也许cmd.exe是最好的选择。哦,Windows... - Dirk Eddelbuettel
@Joshua Ulrich @Dirk Eddelbuettel,我已经纠正了两个问题,现在可以编译了!但是,现在它说找不到我特别安装的Rcpp和RInside包。明天会深入研究! - Christian Bøhlke
这将是您本地 R 使用的问题,因为 Makefile 要求 R 告诉它 Rcpp 和 RInside 的位置,但 R 不知道。 - Dirk Eddelbuettel
3个回答

6

我在工作中有类似的设置,所以我尝试了一下。在我指定R_LIBS_SITE之后,我能够构建这些示例。请注意,它必须是Windows路径,而不是Cygwin路径!

export R_LIBS_SITE=c:/R/site-library

我倾向于在我的~/.Renvironment中这样说。Makefile假定R知道它的软件包。我们必须能够查询Rcpp和RInside关于它们的路径。但是如果你有一个好的建议,给我发送一个两行的代码,我们可以添加到Makefile.win中。 - Dirk Eddelbuettel
@Dirk:我也是……在Linux上。;-) 我已经在R_HOME/etc/Rcmd_environ中指定了它,但它没有被捕获。如果我从shell导出它,它就可以工作。 - Joshua Ulrich
好的,从记忆中来看,还有Renviron.site,以及我之前写过的~/.R*;否则请参见help(Startup)。 - Dirk Eddelbuettel
1
在我的 RProfile.site 文件中设置 .Library.site <- file.path("C:/R/R-2.12.2/library") 是解决方法!非常感谢你的帮助!希望能在即将到来的芝加哥 RInFinance 大会上见到你们中的一些人! - Christian Bøhlke

6
您似乎有两个明显的问题:
1. 您的$PATH可能有误,或者像Josh暗示的那样,您的$R_HOME分配错误。如果make确实是来自Rtools的二进制文件,并且您分配的路径正确,则构建将成功。这是在Windows上构建R软件包的一般规则:非常认真地遵循手册,它就会起作用。
2. RInside在Windows上无法正常工作,很抱歉。它将会构建,但您将会得到段错误。Romain和我在文档中明确说明了这一点。
由于Romain和我几乎只在OS X和Linux上工作,因此我们需要调试帮助。这应该是可行的,但可能需要一些严肃的意愿来学习关于R内部的知识,因为某些内存子系统出现了问题。而在名称中带有X的操作系统上显然不会出现这种情况。
更新于2011年12月8日:RInside 0.2.5,今天已经在CRAN上发布,恢复了Windows功能--使用James在其他评论中提到的修复方法。

4

今天我花了一点时间研究RInside的Windows版本中的一个错误。我相信我已经发现了这个错误,其具体情况如下:

在RInside :: initialize(...)中,填充structRStart结构体,但在Windows情况下,需要填充更多字段,如Rf_initEmbeddedR()所示,该函数位于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;

等效的赋值语句将在 RInside.cpp 中是必要的,以提供有效的回调函数。

詹姆斯在私人電子郵件中友善地向我報告了這一點,看起來很有前途。目前我沒有Windows電腦的訪問權限,如果有人想要測試這個,請聯繫我,因為我發送了幾封跟進的電子郵件給詹姆斯,但我想他已經睡了。相關結構在RStartup.h中定義,在Windows上以#ifdef顯示的字段在此處顯示。 - Dirk Eddelbuettel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接