如何在Windows XP平台上让Rcpp在R中工作?

4

我一直在尝试在Windows XP平台上的R 2.14.2中使用Rcpp。据我所知,我遵循了所有建议的步骤来使Rcpp工作:

  1. 我将R安装在名为C:\R\R-2.14.2的目录中;
  2. 我在目录C:\R\Rtools中安装了最新版本的Rtools;
  3. 我按照如下顺序设置了环境PATH:

C:\R\Rtools\bin;C:\R\Rtools\gcc-4.6.3\bin;
C:\R\R-2.14.2\bin\i386;C:\WINDOWS;C:\WINDOWS\system32

尽管如此,当我尝试在R中运行一个测试示例以检查Rcpp是否有效时,出现了错误消息。这是测试示例:

library(Rcpp)
library(inline)

body <- '
NumericVector xx(x);
return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'

add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp")

x <- 1
y <- 2
res <- add(c(x, y))
res

以下是R尝试执行上述R代码时产生的相当长的错误消息。请问我做错了什么,还需要做什么才能确保Rcpp正常工作?

cygwin warning:
MS-DOS style path detected: C:/R/R-214~1.2/etc/i386/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R/R-214~1.2/etc/i386/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
g++.exe: error: C:/Documents: No such file or directory
g++.exe: error: and: No such file or directory
g++.exe: error: Settings/dv6110ca/My: No such file or directory
g++.exe: error: Documents/R/win-library/2.14/Rcpp/lib/i386/libRcpp.a: No such file  
or directory

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
1: 
2: // includes from the plugin
3: 
4: #include <Rcpp.h>
5: 
6: 
7: #ifndef BEGIN_RCPP
8: #define BEGIN_RCPP
9: #endif
10: 
11: #ifndef END_RCPP
12: #define END_RCPP
13: #endif
14: 
15: using namespace Rcpp;
16: 
17: 
18: // user includes
19: 
20: 
21: // declarations
22: extern "C" {
23: SEXP file684203c3ec2( SEXP x) ;
24: }
25: 
26: // definition
27: 
28: SEXP file684203c3ec2( SEXP x ){
29: BEGIN_RCPP
30: 
31: NumericVector xx(x);
32: return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));
33: END_RCPP
34: }
35: 
36: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
Compilation ERROR, function(s)/method(s) not created! cygwin warning:
MS-DOS style path detected: C:/R/R-214~1.2/etc/i386/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R/R-214~1.2/etc/i386/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
g++.exe: error: C:/Documents: No such file or directory
g++.exe: error: and: No such file or directory
g++.exe: error: Settings/dv6110ca/My: No such file or directory
g++.exe: error: Documents/R/win-library/2.14/Rcpp/lib/i386/libRcpp.a: No such file or  
directory
3个回答

4
不要把R安装在路径名中包含空格的目录中。我记得这个建议在“Windows下的R常问问题”中提到过。
我个人的偏好是始终将其安装在c:\opt\R-current\而不是默认路径中的版本化路径。

3
错误信息在你发布的消息的最后5行中解释:
g++.exe: error: C:/Documents: No such file or directory
g++.exe: error: and: No such file or directory
g++.exe: error: Settings/dv6110ca/My: No such file or directory
g++.exe: error: Documents/R/win-library/2.14/Rcpp/lib/i386/libRcpp.a: No such file or  
directory

g++.exe正在寻找名为libRcpp.a的文件,但该文件位于名称中带有空格的文件夹中,在您的计算机上,该文件位于此文件夹中:

C:/Documents and Settings/dv6110ca/My Documents/R/win-library/2.14/Rcpp/lib/i386/libRcpp.a

如果文件夹路径中包含3个空格(在 Documentsand 之间,在 andSettings 之间,在 MyDocuments 之间),那么您的编译器/链接器可能无法处理这些空格。


2
我遇到了设置Rcpp的同样问题。看起来你卸载了R并重新安装它以创建与Rcpp兼容的设置。这样做后,R将在与先前安装相同的文件夹中安装软件包。卸载R后,请确保删除保存软件包的文件夹。在我的Windows 7机器上,这个文件夹位于C:/Users/Chandler/R。删除此文件夹;然后重新安装R。确保新的软件包被安装在新的R文件夹中,例如C:\R\R-2.14.2\library。这应该消除Dirk上面提到的文件夹位置中的空格问题。
另外,请确保路径与“R安装和管理”手册附录D中的示例相同。如果您使用最新版本的R而不是2.14.2,则可以更轻松地遵循此手册。
注意:尽管Rcpp有效,我仍然会收到cygwin警告。

2
也许在 OP 发布的信息中提到的 CYGWIN 环境变量选项 "nodosfilewarning" 语句可以帮助关闭警告。 - Alessandro Jacopson

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