rcpp

Efficiently randomly drawing from a multivariate normal distribution

五迷三道 提交于 2019-12-01 18:18:34
Just wondering if anyone has ever encountered the problem where he/she needs to randomly draw from a very high dimensional multivariate normal distribution (say dimension = 10,000), as the rmvnorm function of the mvtnorm package is impractical for that. I know this article has an Rcpp implementation for the dmvnorm function of the mvtnorm package, so I was wondering if something equivalent exists for rmvnorm ? Here's a quick comparison of mvtnorm::rmvnorm and an Rcpp implementation given here by Ahmadou Dicko. The times presented are for 100 draws from a multivariate normal distribution with

Can't use Rcpp engine in R Markdown

大憨熊 提交于 2019-12-01 16:50:38
I tried to Knit HTML the following Rmd file: --- title: "Untitled" author: "Florian Privé" date: "12 septembre 2016" output: html_document --- ```{r fibCpp, engine='Rcpp'} #include <Rcpp.h> // [[Rcpp::export]] int fibonacci(const int x) { if (x == 0 || x == 1) return(x); return (fibonacci(x - 1)) + fibonacci(x - 2); } ``` I got the following error: Building shared library for Rcpp code chunk... Warning message: l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-33~1.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB

Error when compiling Rcpp code in an R package using RStudio

荒凉一梦 提交于 2019-12-01 15:11:19
I am using Rstudio to create a package, and exploring the use of the Rcpp package to gain access to C++ code, however, when trying to build the package, and error is being thrown as follows: fatal error: Rcpp.h: No such file or directory Inline C++ code compiles fine, its only when considering standalone C++ files in the src folder, obviously referring to the #include <Rcpp.h> directive at the head of the .cpp file. I think it may have something to do with environment variables, does anyone know what the correct configuration is and how to fix for Rstudio operating in an Ubuntu 12.04 LTS

Error when compiling Rcpp code in an R package using RStudio

爷,独闯天下 提交于 2019-12-01 14:02:54
问题 I am using Rstudio to create a package, and exploring the use of the Rcpp package to gain access to C++ code, however, when trying to build the package, and error is being thrown as follows: fatal error: Rcpp.h: No such file or directory Inline C++ code compiles fine, its only when considering standalone C++ files in the src folder, obviously referring to the #include <Rcpp.h> directive at the head of the .cpp file. I think it may have something to do with environment variables, does anyone

RStudio crashes *after* calling an Rcpp function multiple times

非 Y 不嫁゛ 提交于 2019-12-01 12:14:38
I've written some Rcpp code to find intersections in two piecewise linear curves. I approached the problems in the naive way requiring nested loops (checking all pairs of segments), so went to Rcpp for speed. (The problem is pictorially described in "Example 1" here: https://prezi.com/rwkji_leuwdr/r-and-c-integration/ ) The code compiles fine with sourceCpp, and even runs fine and gives expected results. BUT, the strange issue is that it consistently crashes RStudio either after running it multiple times (say, 5 or 6), or a little while after running it. I haven't seen anyone else document

Rcpp with quad precision computation

走远了吗. 提交于 2019-12-01 12:11:24
问题 What is the best way to numerically compute things like the following within Rcpp? exp(-1500)/(exp(-1500)+exp(-1501)) In many cases, the computation may require multi precision (for the exp), but the end result can be rounded to a usual double. Via quadmath? Via boost? If you stay in R (outside of Rcpp), there are really comfy wrappers to do the job: library(Rmpfr) a = mpfr(-1500,100) b = mpfr(-1501,100) exp(a)/(exp(a)+exp(b)) But how to access with rcpp? 回答1: A quick way to get up and

RStudio crashes *after* calling an Rcpp function multiple times

微笑、不失礼 提交于 2019-12-01 11:54:15
问题 I've written some Rcpp code to find intersections in two piecewise linear curves. I approached the problems in the naive way requiring nested loops (checking all pairs of segments), so went to Rcpp for speed. (The problem is pictorially described in "Example 1" here: https://prezi.com/rwkji_leuwdr/r-and-c-integration/ ) The code compiles fine with sourceCpp, and even runs fine and gives expected results. BUT, the strange issue is that it consistently crashes RStudio either after running it

Do I need to import RccpEigen in the DESCRIPTION file for an R package using it, or is “LinkingTo” enough?

ⅰ亾dé卋堺 提交于 2019-12-01 09:12:05
I used the RcppEigen.package.skeleton() as a template for adding a small function to an existing R package, so that my DESCRIPTION file now has the lines: Imports: Rcpp (>= 0.11.3), RcppEigen (>= 0.3.2.3.0) LinkingTo: Rcpp, RcppEigen However, doing R CMD check --as-cran <myPackageName_1.0.0>.tar.gz gives the following: "Package in Depends/Imports which should probably only be in LinkingTo: 'RcppEigen'" The Writing R Extensions page says: "Specifying a package in ‘LinkingTo’ suffices if these are C++ headers containing source code or static linking is done at installation: the packages do not

Rcpp implementation of mvtnorm::pmvnorm slower than original R function

人盡茶涼 提交于 2019-12-01 08:19:04
问题 I am trying to get a Rcpp version of pmvnorm to work at least as fast as mvtnorm::pmvnorm in R. I have found https://github.com/zhanxw/libMvtnorm and created a Rcpp skeleton package with the relevant source files. I have added the following functions which make use of Armadillo (since I'm using it across other code I've been writing). //[[Rcpp::export]] arma::vec triangl(const arma::mat& X){ arma::mat LL = arma::trimatl(X, -1); // omit the main diagonal return LL.elem(arma::find(LL != 0)); }

How to debug (line-by-line) Rcpp generated code in Windows?

怎甘沉沦 提交于 2019-12-01 05:16:48
问题 I am trying to debug Rcpp compiled code at run-time. I have been trying to get this to work unsuccessfully, for a very long time. A very similar question was asked here: Debugging (line by line) of Rcpp-generated DLL under Windows which asks the same question, but both the question and the answer are far beyond my understanding. Here is what I have: Windows 7 Pro SP1 R 3.5 Rstudio 1.1.463 with Rcpp. Rbuild Tools from Rstudio. (c++ compiler) Procedure: In Rstudio File->New File->C++ File