rcpp

Rcpp Armadillo: RStudio says “exp” is ambiguous

允我心安 提交于 2019-12-12 18:28:42
问题 I'm trying out Rcpp / RcppArmadillo in RStudio with the following code: #include <RcppArmadillo.h> //[[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using std::exp; using std::log1p; // [[Rcpp::export]] arma::vec log1pexp(arma::vec x) { for(int ii = 0; ii < x.n_elem; ++ii){ if(x(ii) < 18.0){ x(ii) = log1p(exp(x(ii))); } else{ x(ii) = x(ii) + exp(-x(ii)); } } return x; } RStudio says the calls to exp are ambiguous. I've tried calling std::exp in the code instead of using std::exp but

Accessing Named List Elements in Rcpp

泪湿孤枕 提交于 2019-12-12 17:01:32
问题 I would like to access a named list element by name in Rcpp In R > b = list(bgroups=c(1,1,1,1,1,0,0,0,0,0)) > b$bgroups [1] 1 1 1 1 1 0 0 0 0 0 Then when trying to access this in Rcpp I have tried: cppFunction( " void f(List & b){ std::vector<int> c(10) = as<std::vector<int>> b['bgroups']; } " ) ... NumericVector groupings = b['bgroups']; ... NumericVector groupings(10) = b(4); But to no avail. I've reviewed Dirk's many helpful answers, but have not been able to make the connection https:/

How to export Rcpp Class method with default arguments

£可爱£侵袭症+ 提交于 2019-12-12 16:22:02
问题 I have a c++ class myClass which has a method foo(int x=0) and it has a parameter x with default value = 0. The c++ class could be exported to R by RCPP_MODULE(my_module) { class_< myClass >( "myClass" ) .constructor() .method( "foo", &myClass::foo ) ; } However, in R, I am not able to call myClass$foo without specifying the value of x . I have to specify the value of x regardless the default value. So my question is how to export Rcpp class method with default arguments. I tried to search it

Rcpp sourceCpp with parallel foreach

那年仲夏 提交于 2019-12-12 15:05:52
问题 I have a function foo written in Rcpp which I can utilize in my R session through sourceCpp. I also have a cluster of machines using R's parallel makePSOCKCluster. I want to run a parallel foreach loop across these machines which will utilize foo. I can see the function being exported through foreach, but I think only the pointer to the Rcpp function is exported. How can I make sure that the function foo itself is also exported? 来源: https://stackoverflow.com/questions/26418655/rcpp-sourcecpp

R recompile packages failing because failing

北慕城南 提交于 2019-12-12 13:40:52
问题 On my linux cluster, I am having trouble recompiling R packages that need to be recompiled with the removal of libRcpp.so in the latest release. The end goal is to get the R package DEseq2 running. We have installed a new version of g++ in /opt/bin directory have new libraries in /opt/lib64 . I have also created .R/Makevars that has these directives: CXX=/opt/bin/g++ -Wl,-rpath,/opt/lib64 -Wl,-L,/opt/lib64 -Wl,-llibstdc++ CC=/opt/bin/c++ -Wl,-rpath,/opt/lib64 -Wl,-L,/opt/lib64 -Wl,-llibstdc++

Rcpp Parallel or openmp for matrixvector product

大兔子大兔子 提交于 2019-12-12 12:27:05
问题 I am trying to program the naive parallel version of Conjugate gradient, so I started with the simple Wikipedia algorithm, and I want to change the dot-products and MatrixVector products by their appropriate parallel version, The Rcppparallel documentation has the code for the dot-product using parallelReduce; I think I'm gonna use that version for my code, but I'm trying to make the MatrixVector multiplication, but I haven't achieved good results compared to R base (no parallel) Some

Is it possible to build an R package, which use Rcpp and Boost.Thread, on [win-builder](http://win-builder.r-project.org/)?

微笑、不失礼 提交于 2019-12-12 11:52:53
问题 Recently, I have made an R package, which use Rcpp to integrate R and C++. And the C++ library Boost is used for multithreading. I wonder if is it possible for my package to be built on http://win-builder.r-project.org/? I found that a Make variable --- BOOSTLIB --- is defined, as shown in http://cran.r-project.org/bin/windows/contrib/ThirdPartySoftware.html. I tried to use the header-only libraries, it's OK, but when I tried to use separately-compiled library Boost.Thread, either "no such

List of matrices multiplied by a scalar, dimension attributes are not preserved in Rcpp

坚强是说给别人听的谎言 提交于 2019-12-12 11:22:43
问题 I am using Rcpp to speed up some R codes (and actually this is one of the items of my 'to do' List for 2014), part of the code consists of multiplying a list of matrices by a scalar, I am able to get the results, nontheless the matrices are not longer matrices, they are vectors instead and I want a list of matrices as the final output. Here's the code I have so far: // [[Rcpp::depends(RcppArmadillo)]] #include <RcppArmadillo.h> using namespace Rcpp; using namespace arma; // I got this

cannot compile RcppArmadillo in R

青春壹個敷衍的年華 提交于 2019-12-12 11:14:39
问题 I have a problem to compile RcppArmadillo. This is the result when I try to install the package: > install.packages("RcppArmadillo") Installing package(s) into ‘/home/*****/R/i686-pc-linux-gnu-library/2.15’ (as ‘lib’ is unspecified) trying URL 'http://cran.rstudio.com/src/contrib/RcppArmadillo_0.3.4.4.tar.gz' Content type 'application/x-gzip' length 742125 bytes (724 Kb) opened URL ================================================== downloaded 724 Kb Loading required package: survival Loading

Loading Rcpp and Running Sample Code

白昼怎懂夜的黑 提交于 2019-12-12 10:45:24
问题 I am fairly new to R and am having an issue with Rcpp. From this URL http://www.r-bloggers.com/installing-rcpp-on-windows-7-for-r-and-c-integration/ I have followed all steps for installing Rcpp. I also installed and loaded RcppClassic and Rinside. When I try to run the code suggested: # install packages install.packages(c("Rcpp", "rbenchmark", "inline", "Runit")) # load main two packages library(Rcpp) library(inline) # do something with Rcpp to quickly check that it works body <- '