0

我对 RInside + Rcpp + R + C++ + windows 的故事很陌生。我试图通过成功编译和运行 RInside 示例来让事情顺利进行。我设法克服了许多最初的问题(比如这个),最后设法构建了 64 位 RInside 示例可执行文件。

我正在运行最新版本的 R 和最新版本的 RTools。我通过运行从源代码构建了 RInside 和 RCPP

install.packages(c("Rcpp","RInside"),type="source")

否则我只能构建 x86 二进制文件(我无法在我的 64 位 Windows 服务器操作系统上运行)。从 R 控制台一切正常。以下示例通过,没有任何错误:

body <- '
+ NumericVector xx(x);
+ return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'
> 
> add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp")
cygwin warning:
  MS-DOS style path detected: C:/R-215~1.0/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R-215~1.0/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
> 
> x <- 1
> y <- 2
> res <- add(c(x, y))
> res
[1] 3
> #[1] 3

但是当我尝试运行 RInside 示例时,我收到以下错误:

Error in paste0("(^|[^%])(%%)*%", spec) : not a BUILTIN function
Error in paste0("^", pkg, "$") : not a BUILTIN function
Execution halted

有谁知道发生了什么?

提前非常感谢。

编辑:更详细的 R 2.15.0 问题重现。

我将 CRAN 的最新版本安装到 C:\R-2.15.0 Ran 64bit RGUI.exe 并执行install.packages(c("Rcpp","RInside"),type="source") Changed Makefile.win 以强制 x64 架构并指向正确的安装目录。

## -*- mode: makefile; tab-width: 8; -*-
##
## Simple Makefile for Windows

## This version is fairly directly derived from the Unix versions
## You may have to set R_HOME manually if this does not work
## It requires Rtools in the path -- as does all R package building
#R_HOME :=      $(shell R RHOME | sed -e "s|\\\\|\/|g")
R_HOME := "C:\R-2.15.0"
#R_HOME := "C:\R-2.14.1"
#R_HOME := "C:\R-2.14.2"

## You may have to set this to one of the two values to enforce a particular architecture
#R_ARCH :=      --arch i386
R_ARCH :=       --arch x64

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

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


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


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


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


all :           $(programs)


clean:
            rm -vf $(programs)


checkR:
            echo "R is at $(R_HOME)"

跑 make -f Makefile.win

cygwin warning:
  MS-DOS style path detected: C:\R-2.15.0/bin/R
  Preferred POSIX equivalent is: /cygdrive/c/R-2.15.0/bin/R
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  atomic.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -LC:/R-2
.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a" C:/R-
2.15.0/library/Rcpp/lib/x64/libRcpp.a -o atomic
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_callbacks0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRb
las -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRIns
ide.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_callbacks0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_module_sample0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64
-lRblas -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/lib
RInside.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_module_sample0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample1.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample1
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample10.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRbla
s -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInsid
e.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample10
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample11.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRbla
s -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInsid
e.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample11
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample2.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample2
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample3.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample3
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample4.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample4
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample5.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample5
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample6.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample6
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample7.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample7
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample8.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample8
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_sample9.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas
 -LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside
.a" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_sample9
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_test0.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -
LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a
" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_test0
g++ -m64 -IC:/R-2.15.0/include -IC:/R-2.15.0/include/x64 -IC:/R-2.15.0/library/R
cpp/include -IC:/R-2.15.0/library/RInside/include -O2 -Wall -mtune=core2 -Wall
-s  rinside_test1.cpp  -LC:/R-2.15.0/bin/x64 -lR -LC:/R-2.15.0/bin/x64 -lRblas -
LC:/R-2.15.0/bin/x64 -lRlapack "C:/R-2.15.0/library/RInside/lib/x64/libRInside.a
" C:/R-2.15.0/library/Rcpp/lib/x64/libRcpp.a -o rinside_test1

我得到了可执行文件,但是当我尝试运行其中任何一个时,都会出现以下错误。

Error in paste0("(^|[^%])(%%)*%", spec) : not a BUILTIN function
Error in paste0("^", pkg, "$") : not a BUILTIN function
Execution halted
4

2 回答 2

2

请将完整且可重现的示例发布到rcpp-devel 邮件列表。请注意,您需要订阅列表中的帖子;否则使用Gmane 订阅之类的东西。

RInside 绝对可以在 Windows 下运行,因为我们修复了初始化问题。您必须输入make -f Makefile.win,而不仅仅是make. 发布具有可重现来源的完整命令和完整的错误日志。

于 2012-05-17T13:43:36.077 回答
0

抱歉,我花了这么长时间才重新审视这个问题。

最后,我只是回到了以前版本的 R (2.14.2),它开箱即用。所以我猜想 2.15.1.0 和 RInside 的协作存在一些问题。如果我有时间,我会尝试进一步调查。

于 2012-05-22T11:05:03.870 回答