rcpp

Multiple plugins in cxxfunction

牧云@^-^@ 提交于 2019-12-12 09:40:51
问题 I want to use RcppGSL and RcppArmadillo at the same time, is that possible to use multiple plugins in cxxfunction (of the inline CRAN package) ? I found a way to do: plug.ArmaGSL <- Rcpp:::Rcpp.plugin.maker(include.before='#include <RcppArmadillo.h> #include <RcppGSL.h> #include <gsl/gsl_rng.h>', Depends=c("RcppGSL", "RcppArmadillo", "Rcpp"), LinkingTo=c("RcppGSL", "RcppArmadillo", "Rcpp"), libs="-lgsl -larmadillo") registerPlugin("RcppArmaGSL", plug.ArmaGSL) foo <- cxxfunction(signature(sM=

implementing apply function in Rcpp

耗尽温柔 提交于 2019-12-12 09:39:43
问题 I have been trying to implement apply function in Rcpp so far the code looks like this //[[Rcpp::export]] NumericVector apply(NumericMatrix x,int dim,Function f){ NumericVector output; if(dim==1){ for(int i=0;i<x.nrow();i++){ output[i]=f(x(i,_)); } } else if(dim==2){ for(int i=0;i<x.ncol();i++){ output[i]=f(x(_,i)); } } return(output); } but i'm getting an error "cannot convert SEXP to double in assignment" in line 6 and 11. Is there any way to convert the value returned by an arbitrary

Rcpp rank function that does average ties

[亡魂溺海] 提交于 2019-12-12 08:58:38
问题 I have a custom rank function that I stole from here (with some modifications) :) Rcpp sugar for rank function The problem is that it does min ties and I need average ties Here is what I have #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector sort_rcpp(NumericVector x) { std::vector<double> tmp = Rcpp::as< std::vector<double> > (x); std::sort(tmp.begin(), tmp.end()); return wrap(tmp); } // [[Rcpp::export]] IntegerVector rank_(NumericVector x) { return match(x, sort_rcpp

How to set up Eclipse + StatET + Rcpp on Windows

巧了我就是萌 提交于 2019-12-12 08:33:09
问题 When I came to know that I can create a R package with C++ using Rcpp, I was excited about it and eager to know development environment for it. And thanks to Fell Stat Blog, I could quickly establish a great environment using Eclipse with StatET, its plugin for R, to use Rcpp and RInside (another package for embedding R into your C++ application) on Windows. Since the blog was, however, based on OS X, several things required trial & error (& almost give-up) to adjust for Windows - it took me

Rcpp + inline - creating and calling additional functions

断了今生、忘了曾经 提交于 2019-12-12 08:08:12
问题 I would like to know if there is a way to create Rcpp functions using the inline packages within the main function. This is an example of what I want to do: library(inline) library(Rcpp) a = 1:10 cpp.fun = cxxfunction(signature(data1="numeric"), plugin="Rcpp", body=" int fun1( int a1) {int b1 = a1; b1 = b1*b1; return(b1); } NumericVector fun_data = data1; int n = data1.size(); for(i=0;i<n;i++){ fun_data[i] = fun1(fun_data[i]); } return(fun_data); ") which should result in: > cpp.fun(a) [1] 1

RcppArmadillo and C++ division issue

一笑奈何 提交于 2019-12-12 06:32:07
问题 A very simple question regarding RcppArmadillo. Trying to multiply a vector by a scalar, and getting different results depending on small changes in syntax. Any ideas? // [[Rcpp::depends("RcppArmadillo")]] // [[Rcpp::export]] arma::vec funtemp(arma::vec x) { // return(x/10); // this works // return((1/10)*x); // this does not work return(x*(1/10)); // this does not work } 回答1: Ahh, the good ol' integer vs. double division problem in C++. Before we begin, note that: arma::vec is by default a

Building (and running) RInside examples under windows

岁酱吖の 提交于 2019-12-12 05:37:20
问题 I am quite new to the RInside + Rcpp + R + C++ + windows story. I am trying to get things going by successfully compiling and running RInside examples. I managed to overcome many initial problems (like this one), and finally managed to build 64bit RInside example executables. I am running the newest version of R the newest version of RTools. I built RInside and RCPP from source by running install.packages(c("Rcpp","RInside"),type="source") Otherwise I was only able to build x86 binary (which

Rcpp - how to use a distribution function in the C++ code [duplicate]

我是研究僧i 提交于 2019-12-12 04:23:39
问题 This question already has an answer here : Using dnorm with RcppArmadillo (1 answer) Closed 2 years ago . I'm writing a Metropolis-Hastings algorithm for a N(0,1) distribution: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector metropolis(int R, double b, double x0){ NumericVector y(R); y(1) = x0; for(int i=1; i<R; ++i){ y(i) = y(i-1); double xs = y(i)+runif(1, -b,b)[0]; double a = dnorm(xs, 0, 1)[0]/dnorm(y(i), 0, 1)[0]; NumericVector A(2); A(0) = 1; A(1) = a; double

Rcpp package in R not install ubuntu 14.04

风格不统一 提交于 2019-12-12 04:23:37
问题 please help me in this. I tried installing Rcpp using sudo apt-get install r-cran-rcpp and from R-Studio and got the same error: > install.packages("Rcpp", dependencies=TRUE) Installing package into ‘/home/sukumar/R/x86_64-pc-linux-gnu-library/3.3’ (as ‘lib’ is unspecified) also installing the dependency ‘highlight’ trying URL 'http://cran.rstudio.com/src/contrib/highlight_0.4.7.tar.gz' Content type 'application/x-gzip' length 356443 bytes (348 KB) ============================================

Able To Reference Functions But, Not Classes in a Namespace

﹥>﹥吖頭↗ 提交于 2019-12-12 03:49:50
问题 I'm able to reference functions from a namespace but, not classes. Here is the namespace file SeqLib/FermiAssembler.h" #ifndef SEQLIB_FERMI_H #define SEQLIB_FERMI_H #include <string> #include <cstdlib> #include <iostream> namespace SeqLib { void print_my_name(){ std::cout << "It's Crt" } class FermiAssembler { public: FermiAssembler(); ~FermiAssembler(); void AddReads(const BamRecordVector& brv); }; } I am able to call print_my_name() via SeqLib::print_my_name() but, not able to reference the