我正在通过 Hadley 的教程在这里学习使用 Rcpp 。但是,当我将以下代码放入名为 .cpp 的文件中时scalar_missing.cpp
# include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List scalar_missings() {
int int_s = NA_INTEGER;
String chr_s = NA_STRING;
bool lgl_s = NA_LOGICAL;
double num_s = NA_REAL;
return List::create(int_s, chr_s, lgl_s, num_s);
}
/*** R
str(scalar_missings())
*/
然后在R中,我sourceCpp("scalar_missing.cpp")
用来运行,我收到以下错误:
'String was not declared in this scope'
什么地方出了错?我sessionInfo
的是
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] Rcpp_0.10.1
loaded via a namespace (and not attached):
[1] tools_2.15.1
非常感谢!