标签: rcpp11

#include <Rcpp11>找不到文件错误

我试图Rcpp11在它的源代码中使用r中的包:

devtools::install_github("Rcpp11/Rcpp11")
Run Code Online (Sandbox Code Playgroud)

我在这里阅读:http://blog.r-enthusiasts.com/2014/05/27/disambiguating-rcpp11-and-rcpp/

我可以在我的文件的头部使用include <Rcpp11>+ 但我在采购时遇到此错误:using namespace Rcpp11.cpp

 egfile.cpp:1:10: fatal error: 'Rcpp11' file not found
 #include <Rcpp11>
           ^
 1 error generated.
Run Code Online (Sandbox Code Playgroud)

其中egfile.cpp:

#include <Rcpp11>
using namespace Rcpp11;

// Below is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp 
// function (or via the Source button on the editor toolbar)

// For more on using …
Run Code Online (Sandbox Code Playgroud)

r rstudio rcpp11

6
推荐指数
1
解决办法
679
查看次数

NumericVector和vector <double>之间是否存在性能差异?

假设一个人使用NumericVector,另一个人使用vector<double>他们的Rcpp代码.两种用法之间是否存在显着差异,尤其是在性能方面?

r rcpp rcpp11

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

最近点的路径

我有两组积分,叫做pathcenters.对于每个点path,我想要一种有效的方法来找到最近点的ID centers.我想在R中这样做.下面是一个简单的可重复的例子.

set.seed(1)
n <- 10000
x <- 100*cumprod(1 + rnorm(n, 0.0001, 0.002))
y <- 50*cumprod(1 + rnorm(n, 0.0001, 0.002))

path <- data.frame(cbind(x=x, y=y))

centers <- expand.grid(x=seq(0, 500,by=0.5) + rnorm(1001), 
                       y=seq(0, 500, by=0.2) + rnorm(2501))

centers$id <- seq(nrow(centers))
Run Code Online (Sandbox Code Playgroud)

x并且y是坐标.我想在pathdata.frame中添加一列,它具有给定x和y坐标的最近中心的id.然后我想获得所有独特的ID.

我的解决方案目前确实有效,但当问题的规模增加时,它的速度非常慢.我想要更高效的东西.

path$closest.id <- sapply(seq(nrow(path)), function(z){
   tmp <- ((centers$x - path[z, 'x'])^2) + ((centers$y - path[z, 'y'])^2)
   as.numeric(centers[tmp == min(tmp), 'id'])
})

output <- unique(path$closest.id)
Run Code Online (Sandbox Code Playgroud)

任何有关加快这一点的帮助将不胜感激.

我认为data.table可能有所帮助,但理想情况下我所寻找的是一种算法,在搜索方面可能更聪明,即不是计算到每个中心的距离,而是只选择最小的...获取id ... …

performance r spatial rcpp rcpp11

4
推荐指数
2
解决办法
1367
查看次数

在Rcpp中声明一个变量作为引用

在C++中,我们可以将变量声明为引用.

int a = 10;
int& b = a;
Run Code Online (Sandbox Code Playgroud)

如果我们设置b=15,a也会改变.

我想在Rcpp做类似的事情.

List X = obj_from_R["X"];
IntegerVector x_i = X[index];
x_i = value;
Run Code Online (Sandbox Code Playgroud)

我想X通过在其向量之一中插入一个值来更新R中的对象.上面的代码不起作用,所以我尝试了这个:

IntegerVector& x_i = X[index];
Run Code Online (Sandbox Code Playgroud)

并收到错误.

error: non-const lvalue reference to type 'IntegerVector'
      (aka 'Vector<13>') cannot bind to a temporary of type 'Proxy' (aka 'generic_proxy<19>')
Run Code Online (Sandbox Code Playgroud)

rcpp rcpp11

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

从 Rcpp 中调用 igraph

作为在进一步处理之前利用随机抽取的网络数据的一部分,我试图igraph在每次迭代开始时从包中调用几个函数。我使用的代码如下:

#define ARMA_64BIT_WORD
#include <RcppArmadillo.h>

// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::plugins(cpp11)]]
using namespace Rcpp;

using arma::sp_mat;

// [[Rcpp::export]]
sp_mat adj_mat(int n, double p) {

  Environment igraph("package:igraph");
  Function game_er = igraph["erdos.renyi.game"];
  Function get_adjacency = igraph["get.adjacency"];

  List g = game_er(Named("n", n), Named("p", p));

  NumericMatrix A_m = get_adjacency(Named("g", g));

  sp_mat A = as<sp_mat>(A_m);

  return A;
}


/*** R
set.seed(20130810)
library(igraph)

adj_mat(100, 0.5)
*/
Run Code Online (Sandbox Code Playgroud)

因此,虽然 C++ 编译时没有警告,但会抛出以下错误:

> sourceCpp("Hooking-R-in-cpp.cpp")

> set.seed(20130810)

> library(igraph)

> adj_mat(100, 0.5)
Error in adj_mat(100, 0.5) : 
  Not compatible with …
Run Code Online (Sandbox Code Playgroud)

r igraph rcpp rcpp11

3
推荐指数
1
解决办法
317
查看次数

我是否需要在 Imports 和 LinkingTo 中指定 Rcpp 以避免出现 Makevars 文件?

根据Rcpp FAQ(2.15。新的 \xe2\x80\x98no-linking\xe2\x80\x99 功能怎么样),从 Rcpp 版本 0.11.0 开始,我们可以避免在 Makevars 文件中指定 LAPACK/BLAS/Fortran,并且事实上,如果我们遵循这些说明,就可以完全避免 Makevar。

\n\n

\n... only two things are required:\n\xe2\x80\xa2 an entry in DESCRIPTION such as Imports: Rcpp (which\nmay be versioned as in Imports: Rcpp (>= 0.11.0)), and\n\xe2\x80\xa2 an entry in NAMESPACE to ensure Rcpp is correctly instantiated,\nfor example importFrom(Rcpp, evalCpp).\n

\n\n

但是,除了Imports为 Rcpp 添加一行之外,LinkingTo还可以使用 a 吗?也就是说,我可以使用:

\n\n
LinkingTo: Rcpp (>= 0.11.0)\n
Run Code Online (Sandbox Code Playgroud)\n\n

代替:

\n\n
Imports: Rcpp (>= 0.11.0)\n
Run Code Online (Sandbox Code Playgroud)\n\n

还是两者都需要?

\n

r rcpp rcpp11

3
推荐指数
1
解决办法
301
查看次数

Rfast 安装:/usr/lib/R/etc/Makeconf:168:目标“Norm.o”的配方失败

我正在尝试安装 Rfast 包。它给了我以下错误,

/usr/lib/R/etc/Makeconf:168: recipe for target 'Norm.o' failed
    make: *** [Norm.o] Error 1
Run Code Online (Sandbox Code Playgroud)

完整的错误信息是这样的,

> install.packages("Rfast", dependencies = TRUE)

* installing *source* package 'Rfast' ...
** package 'Rfast' successfully unpacked and MD5 sums checked
** libs
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG  -I"/home/haseeb/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/haseeb/R/x86_64-pc-linux-gnu-library/3.4/RcppArmadillo/include"   -fopenmp -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c Diag.cpp -o Diag.o
g++ -std=gnu++11 -I/usr/share/R/include -DNDEBUG  -I"/home/haseeb/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include" -I"/home/haseeb/R/x86_64-pc-linux-gnu-library/3.4/RcppArmadillo/include"   -fopenmp -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-AitvI6/r-base-3.4.4=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c Norm.cpp -o Norm.o
In …
Run Code Online (Sandbox Code Playgroud)

r rcpp rcpp11

3
推荐指数
1
解决办法
1430
查看次数

标签 统计

rcpp11 ×7

r ×6

rcpp ×6

igraph ×1

performance ×1

rstudio ×1

spatial ×1