我一直试图在windows xp平台上使用r 2.14.2中的rcpp。据我所知,我遵循了让rcpp工作的所有建议步骤:
我将r安装在一个名为c:\r-2.14.2;
我在目录C中安装了最新版本的rtools:\r\rtools;
我将环境路径设置为(以完全相同的顺序):
C:\r\rtools\bin;C:\r\rtools\gcc-4.6.3\bin;
C:\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
最佳答案
不要在路径名中包含空格的目录中安装r。我记得,这个建议在“R for Windows常见问题解答”中。
我个人的偏好总是c:\opt\R-current\
而不是版本化的默认路径。