rcpp

Convert rcpp variables into standard C++ variables

萝らか妹 提交于 2019-12-07 03:38:53
问题 My input looks like this: Rcpp::NumericMatrix data(dataMatrix); Rcpp::NumericVector xSize(dataXsize); Rcpp::NumericVector ySize(dataYsize); Rcpp::NumericVector tIndexes(testIndexes); Rcpp::NumericVector cIndexes(controlIndexes); And the external library I'm trying to call has this signature WilcoxonTest(float * _data, int _dataXsize, int _dataYsize, vector<int> * _testIndexes, vector<int> * _controlIndexes); How can I convert the Rcpp data types into C++ standard data types? Note: float *

How to calculate integral, numerically, in Rcpp

匆匆过客 提交于 2019-12-07 03:35:28
I've searched for an hour for the methods doing numerical integration. I'm new to Rcpp and rewriting my old programs now. What I have done in R was: x=smpl.x(n,theta.true) joint=function(theta){# the joint dist for #all random variable d=c() for(i in 1:n){ d[i]=den(x[i],theta) } return(prod(d)*dbeta(theta,a,b)) } joint.vec=Vectorize(joint)##vectorize the function, as required when ##using integrate() margin=integrate(joint.vec,0,1)$value # the ##normalizeing constant at the donominator area=integrate(joint.vec,0,theta.true)$value # the values at the ## numeritor The integrate() function in R

How to get a big sparse matrix in R? (> 2^31-1)

南楼画角 提交于 2019-12-07 03:30:38
问题 I use some C++ code to take a text file from a database and create a dgcMatrix type sparse matrix from the Matrix package. For the first time, I'm trying to build a matrix that has more than 2^31-1 non-sparse members, which means that the index vector in the sparse matrix object must also be longer than that limit. Unfortunately, vectors seem to use 32-bit integer indices, as do NumericVectors in Rcpp. Short of writing an entire new data type from the ground up, does R provide any facility

Call R plots from c++ using RInside/ Rcpp

偶尔善良 提交于 2019-12-07 01:11:58
问题 Is it possible to call the plot functions from the c++ ? Currently when I try to do that, the ubuntu terminal sort of freezes for sometime ( may be the duration for which the 3d plot would be created and then rotated for a full 360 degrees) and then unfreezes, without ever popping a new window. Is this the expected behavior or is there something that I am doing wrong ? How can I get the plots ( R graphics ) to run from within c++ using rinside and rcpp ? Thnx -Egon 回答1: Yes, there is a

faster than scan() with Rcpp?

我与影子孤独终老i 提交于 2019-12-06 23:15:41
问题 Reading ~5x10^6 numeric values into R from a text file is relatively slow on my machine (a few seconds, and I read several such files), even with scan(..., what="numeric", nmax=5000) or similar tricks. Could it be worthwhile to try an Rcpp wrapper for this sort of task (e.g. Armadillo has a few utilities to read text files)? Or would I likely be wasting my time for little to no gain in performance because of an expected interface overhead? I'm not sure what's currently limiting the speed

Saving Lattice Plots with RInside and Rcpp

萝らか妹 提交于 2019-12-06 15:04:51
I am trying to build an R application in C++ using RInside. I wanted to save the plots as images in specified directory using codes, png(filename = "filename", width = 600, height = 400) xyplot(data ~ year | segment, data = dataset, layout = c(1,3), type = c("l", "p"), ylab = "Y Label", xlab = "X Label", main = "Title of the Plot") dev.off() It creates a png file in the specified directory if directly run from R. But using C++ calls from RInside, I was not able to reproduce the same result. ( I could reproduce all base plots using C++ calls. Problem with only Lattice and ggplots ) I used

RcppModules: Manually build/expose C+ classes to R

邮差的信 提交于 2019-12-06 14:40:59
The goal is to wrap fairly large existing collection of C++ classes to be callable from R. The first approach is to manually define R Reference Classes and call into "SEXP-wrapped" entry points - and this works fine, no problems. Another approach that I'm currently evaluating is RcppModules. I can successfully use it with toy example within R - with Rcpp::SourceCPP . But have troubles with doing this manually. Example: //---example.cpp #include "Rcpp.h" using namespace Rcpp; class Example { public: Example(){}; SEXP add(SEXP x_, SEXP y_) const { double x = as<double>(x_); double y = as<double>

Use function defined in one cpp file in function defined in another cpp file in Rcpp

此生再无相见时 提交于 2019-12-06 14:34:33
I have a c++ function called add defined in file add.cpp (content of add.cpp below): #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] double add(double a, double b) { return a + b; } I have another c++ function called multiplyandadd defined in multiplyandadd.cpp file (content of multiplyandadd.cpp below) that calls add function from above: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] double multiplyandadd(double a, double b, double c) { return c*add(a, b); } In order for this to work I figured out I should create a header file add.h in sub folder /inst/include of my

Rcpp: dynamically update a list

夙愿已清 提交于 2019-12-06 13:30:20
I am seeking solutions to dynamically updating a list. #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] List Test(){ List L; List L1=List::create(12,45,22,44); L=Language("c",L,L1).eval();//update, add L1's elements on L's back. return L; } The above doesn't work since "List L;" makes L an empty list. However, if I write an additional function: List connectlist(List& a, List& b){ return Language("c",a,b).eval(); } and replace "L=Language("c",L,L1).eval();" with "connectlist(L,L1);", it will work. Can anyone tell me the reason? Or is there any simpler way to dynamically update a list

Error in sourceCpp after installing Rtools

吃可爱长大的小学妹 提交于 2019-12-06 13:08:33
A month ago I installed Rtools all by default options on my personal computer and was able to write C++ functions in R ever since. Now I am trying to install Rtools on my company's computer and unable to correctly install Rtools. I believe it has something to do with the PATH or some relevant thing that I don't quite understand. Help is so needed. Below are my steps and results: Install R-3.03 in the local drive c; successful install.packages(c("Rcpp","installr")); successful library(installr) install.Rtools() . In this step there's one thing suspicious: I only chose "Save version information