rcpp

Error in sourceCpp after installing Rtools

末鹿安然 提交于 2019-12-07 19:44:21
问题 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

Rcpp debug - fatal error: Datetime.h: No such file or directory; xtsAPI.h: No such file or directory

拜拜、爱过 提交于 2019-12-07 18:26:17
问题 I am using Rcpp to handle Datetime and xts data. However, I'm getting the error No such file or directory error at both lines 2 & 3 of the following code: #include <Rcpp.h> #include <Datetime.h> #include <xtsAPI.h> // [[Rcpp::depends(xts)] using namespace Rcpp; using namespace std; Here's the errors I'm getting: fatal error: Datetime.h: No such file or directory; fatal error: xtsAPI.h: No such file or directory; 回答1: Use #include <Rcpp/Datetime.h> instead of #include <Datetime.h> and make

Calling Rcpp function with Xptr and Function - only xptr case works

穿精又带淫゛_ 提交于 2019-12-07 17:58:15
问题 I am trying to develop a package in which I need to input a function from user (could be defined using Rcpp or in R ), send it to another function (within the package) in a struct and process it there. When I use Rcpp::Xptr (i.e., function pointer) the code works, but the same does not work with Rcpp::Function . The advantage with using Rcpp::Function for the user would be that they would be able to define the function in R (although lose a lot of performance gain). First what works: #include

Passing mean and standard deviation into dnorm() using Rcpp Sugar

筅森魡賤 提交于 2019-12-07 13:38:04
问题 I am converting some R code to Rcpp code and need to calculate the likelihood for a vector of observations given a vector of means and vector of standard deviations. If I assume the means are 0 and the standard deviations 1, I can write this function (running this requires the 'inline' and 'Rcpp' packages to be loaded), dtest1 = cxxfunction(signature( x = "numeric"), 'Rcpp::NumericVector xx(x); return::wrap(dnorm(xx, 0.0, 1.0));', plugin='Rcpp') and the result is as expected. > dtest1(1:3) [1

Concatenate StringVector with Rcpp

旧时模样 提交于 2019-12-07 12:23:13
问题 I can not figure out how to concatenate 2 strings with Rcpp; and the documentation did not help me while I suspect there is an obvious answer. http://gallery.rcpp.org/articles/working-with-Rcpp-StringVector/ http://gallery.rcpp.org/articles/strings_with_rcpp/ StringVector concatenate(StringVector a, StringVector b) { StringVector c; c= ??; return c; } I would expect this output : a=c("a","b"); b=c("c","d"); concatenate(a,b) [1] "ac" "bd" 回答1: There are probably a few different ways to

How do I draw multinomial distributed samples with RcppArmadillo?

大兔子大兔子 提交于 2019-12-07 09:00:18
问题 The problem is that I have a variable arma::mat prob_vec and want something equivalent to rmultinom(1, 1, prob_vec) in R. I found the rmultinom function provided by RcppArmadillo has a weird argument requirement which is different from that in R! So it won't pass the compilation. I just wanna know how to draw the desired sample in RcppArmadillo, or equivalently in Armadillo. If I need to get the pointer or convert my prob_vec variable, please tell me how. Many thanks! 回答1: Your friendly

integer64 and Rcpp compatibility

十年热恋 提交于 2019-12-07 08:28:47
问题 I will need 64 bits integer in my package in a close future. I'm studying the feasibility based on the bit64 package. Basically I plan to have one or more columns in a data.table with an interger64 S3 class and I plan to pass this table to C++ functions using Rcpp. The following nanotime example from Rcpp gallery explains clearly how a vector of 64 bits int is built upon a vector of double and explain how to create an integer64 object from C++ to R. I'm now wondering how to deal with an

Define a matrix in R and pass it to C++

╄→гoц情女王★ 提交于 2019-12-07 06:04:47
问题 I have a matrix defined in R. I need to pass this matrix to a c++ function and do operations in C++. Example: In R, define a matrix, A <- matrix(c(9,3,1,6),2,2,byrow=T) PROTECT( A = AS_NUMERIC(A) ); double* p_A = NUMERIC_POINTER(A); I need to pass this matrix to a C++ function where variable 'data' of type vector<vector<double>> will be initialized with the matrix A. I couldn't seem to figure out how to do this. I am thinking in more complicated way then I should be, I bet there is an easy

Can Rcpp package DLLs be unloaded without restarting R?

家住魔仙堡 提交于 2019-12-07 05:59:15
问题 When installing a Rcpp package on Windows, you need to ensure that the package DLL is unloaded or you get a "Permission Denied" error when copying the new DLL. This means restarting R on every recompile, which is pretty annoying. Is there any way to unload the package DLL without killing R? I've tried the detach("package:my_package", force=TRUE) command, but it doesnt unload the DLL. 回答1: If you want to do this in your main R session (without using RStudio, which makes reinstalling the

Using a different gcc version from that included with Rtools with Rcpp on Windows

99封情书 提交于 2019-12-07 05:10:53
问题 Before I embark on updating gcc, has anyone actually attempted this, and can they confirm building R from source is required to update the gcc version one uses to compile c++ code with Rcpp (i.e. not necessarily for package authoring and certainly not for CRAN-valid packages)? See Dirk's answer to this question, and the follow-on comment from the original poster How to use gcc 4.8.1 with Rcpp on Windows. 回答1: Rebuilding R from source does not appear necessary. Here are the steps I used for a