我正在学习通过Hadley的教程here使用Rcpp。但是,当我将以下代码放入名为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
非常感谢!
答案 0 :(得分:1)
正如已发布的说明中所述,在{rcpp 0.10.2}中添加了Rcpp::String
类。
你可能需要让Hadley在他的教程中澄清需要什么,从哪里获取它。