小编Sco*_*ott的帖子

rcpp函数调用另一个rcpp函数

我猜这是一个简单的问题,但我是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)

r rcpp

14
推荐指数
2
解决办法
4258
查看次数

使用 expand.grid 后反转字典顺序

我正在尝试基于多项式框架生成以下矩阵。例如,如果我有三列,我会得到:

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)

有任何想法吗?谢谢。

r permutation

5
推荐指数
1
解决办法
738
查看次数

Xcode 5.0和OSX 10.8.5和R 3.0.2的Rcpp错误

我只是想在我的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文件的更多细节的参考.

谢谢.

macos xcode r rcpp

4
推荐指数
1
解决办法
1595
查看次数

标签 统计

r ×3

rcpp ×2

macos ×1

permutation ×1

xcode ×1