我猜这是一个简单的问题,但我是Cpp的新手,我被卡住了.
我在R中创建了一个函数,使用Rcpp和:
// [[Rcpp::export]]
Run Code Online (Sandbox Code Playgroud)
我可以在R中调用该函数,它可以按预期工作.我们称之为F1.
接下来,我想创建另一个函数F2,使用Rcpp它调用第一个函数.我使用标准函数调用语言(即,F1(arguments))当我使用时它通过R编译很好sourceCpp().
但是当我试着打电话给F2R时,我得到:
.Primitive中出错(".Call")(
和
缺少F2
第一个.cpp文件包含
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double F1(NumericVector a) {
int n = a.size();
double result=0; // create output vector
double ss = 0;
for(int i = 0; i < n; ++i) {
ss += pow(a[i],2);
}
result = ss;
return result;
}
Run Code Online (Sandbox Code Playgroud)
以下是另一个.cpp文件.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double F2(NumericVector a) …Run Code Online (Sandbox Code Playgroud) 我正在尝试基于多项式框架生成以下矩阵。例如,如果我有三列,我会得到:
0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
1 0 1
0 1 1
1 1 1
Run Code Online (Sandbox Code Playgroud)
但是,我想要更多的列。我知道我可以使用 expand.grid,例如:
u <- list(0:1)
expand.grid(rep(u,3))
Run Code Online (Sandbox Code Playgroud)
但是,它以错误的顺序返回我想要的内容:
0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 1
1 1 1
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢。
我只是想在我的Mac上运行Rcpp,但我正在努力.我安装了命令行工具.我已经安装了Rcpp和内联包.我尝试在R中运行以下脚本,并得到以下错误.
fx <- cxxfunction(signature( x = "numeric" ),
'NumericVector xx(x);
return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));',
plugin = "Rcpp",verbose=TRUE)
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! /bin/sh: llvm-g++-4.2: command not found
make: *** [file2e731b1c0ff8.o] Error 127
Run Code Online (Sandbox Code Playgroud)
我意识到这与发布的问题非常相似.但我很欣赏有关在哪里找到makevars文件的更多细节的参考.
谢谢.