rcpp

Debugging C++ code of an R package with Rcpp using gdb cannot print variable value with R_PV (unknown return type)

送分小仙女□ 提交于 2019-12-11 16:21:50
问题 I have used RStudio on Ubuntu 18.04 to create an hello world R package using Rcpp like described here in Rcpp Package Development: My ~/.R/Makevars contain only the line CXXFLAGS=-g -O0 -Wall and during pkg build I can see that these flags are applied. How can print the current value of an R vector (C++ classes CharacterVector or NumericVector in gdb after hitting a breakpoint? (gdb) p R_PV(x) (as explained in Writing R Extensions) shows an error (perhaps because the SEXP is wrapped?): (gdb)

conflicting declaration error when compiling in Rcpp, but g++ works fine

北城以北 提交于 2019-12-11 14:49:14
问题 I am trying to compile an Rcpp package that relies on the external library HDFql. First, I tried compiling a plain .cpp file following the directions in the reference manual, which worked fine : g++ example.cpp -I./include/HDFql ./HDFql/libHDFql.a -fopenmp -ldl where the ./include/HDFql folder contains the header files and ./HDFql/libHDFql.a is the static library. Then I tried doing the equivalent in an Rcpp package. My package directory structure is |- R |- script. r |- src |- HDFql |-

How to use C++ ODE solver with Rcpp in R?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 13:18:13
问题 To assess the difference in speed to solve ODEs between R and C++, I build the following ODE system in R: modelsir_cpp =function(t,x){ S = x[1] I1 = x[2] I2 = x[3] N=S+I1+I2 with(as.list(parm), { dS=B*I1-mu*S-beta*(S*(I1+I2)/N) dI1=beta*(S*(I1+I2)/N)-B*I1-lambda12*I1 dI2=lambda12*I1 res=c(dS,dI1,dI2) return(res) }) } To solve it, I used the deSolve package. times = seq(0, 10, by = 1/52) parm=c(B=0.01,mu=0.008,beta=10,lambda12=1) xstart=c(S=900,I1=100,I2=0) out = as.data.frame(lsoda(xstart,

Finding duplicates using Rcpp

无人久伴 提交于 2019-12-11 09:23:44
问题 I'm trying to find a speedier replacement for finding duplicates in R. The intent of the code is to pass the matrix to Rcpp with a row number from that matrix, then loop through the entire matrix looking for a match for that row. The matrix in question is a Logical matrix with 1000 rows and 250 cols. Sounds simple, but the code below is not detecting equivalent vector rows. I'm not sure if it's an issue with the equal() function or something in how the matrix or vectors are defined. #include

Undefined reference errors when including Rcpp.h

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 09:23:19
问题 I am using 64bit Ubuntu, and I am trying to write C++. I discovered if I use #include <Rcpp.h> , I don't even need to call any functions in the R namespace, and I would already receive undefired reference errors: obj/x.o: In function `Rcpp::Rstreambuf<true>::xsputn(char const*, long)': /usr/local/lib/R/site-library/Rcpp/include/Rcpp/iostream/Rstreambuf.h:61: undefined reference to `Rprintf' obj/x.o: In function `Rcpp::Rstreambuf<false>::xsputn(char const*, long)': /usr/local/lib/R/site

How to link to boost date_time

此生再无相见时 提交于 2019-12-11 09:07:19
问题 Example I have an Rcpp function where I would like to call boost::posix_time::time_from_string() . I've taken the example code from the boost documentation and translated it to a c++ function using Rcpp library(Rcpp) cppFunction( includes = ' #include <boost/date_time/posix_time/posix_time.hpp> ', code = ' void time_test() { std::string t = "2002-01-20 23:59:59.000"; boost::posix_time::ptime pt(boost::posix_time::time_from_string(t)); Rcpp::Rcout << "time from string: " << pt << std::endl; }

sourceCpp does not work after updating R to 3.4.1

余生长醉 提交于 2019-12-11 08:43:16
问题 I've just updated R from 3.3.1 to 3.4.1. Now I can't use the plugin sourceCpp() to source C++-code. When trying to source the function rcppfunc I get the error: clang: error: unsupported option '-fopenmp' make: *** [rcppfunc.o] Error 1 Before updating everything worked as it should. Has anyone else had similar C++-compiler issues with 3.4.1? 回答1: See the following post explaining how to resolve the -fomp error by enabling OpenMP compilations: http://thecoatlessprofessor.com/programming/openmp

recursive dependence of data - for loop using rcpp

核能气质少年 提交于 2019-12-11 08:04:00
问题 I've got a function written in Rcpp : library(Rcpp) cppFunction("NumericVector MatVecMul_cpp (NumericVector y, double k) { int n = y.size(); NumericVector z(n); int i; double *p1, *p2, *end = &z[n]; double tmp = 1.0; for (i = 0; i < n; i++) { for (p1 = &z[i], p2 = &y[0]; p1 < end; p1++, p2++) *p1 += tmp * (*p2); tmp *= k; } return z; }") Basically the goal of the function is to take a numeric vector and parameter k and to calculate output vector where an i -th element is a sum of i-1 -th

How to deal with an Rcpp::XPtr that may have one of several types

久未见 提交于 2019-12-11 07:46:03
问题 I'm in the situation where I have an Rcpp::XPtr to an Armadillo object (e.g. arma::Mat , which may be a matrix of one of the supported data types). Now I'd like to write a function that queries the number of elements. The best I could come up with so far is the following (inspired by bigstatsr): #define DISPATCH_DATA_TYPE(CALL) \ { \ switch (data_type) \ { \ case 1: CALL(unsigned short) \ case 2: CALL(unsigned int) \ case 3: CALL(unsigned long) \ case 4: CALL(short) \ case 5: CALL(int) \ case

R Prophet crashing Rstudio in loop

送分小仙女□ 提交于 2019-12-11 07:05:47
问题 I've been using prophet in R on windows for several months now and have recently started seeing random RStudio crashes. Prior to a few days ago, I was having no issues. I know that's not much to go off of, but I'm hoping someone can recognize what might be going on with my system. I've noticed that it crashes more frequently when n.changepoints is higher than the default of 25. I see the crashes on both R 3.4 and 3.5. I have Rtools installed properly and can compile cpp code inline as