rcpp

Rcpp: Inconsistent behavior with proxy model

房东的猫 提交于 2019-12-12 03:36:25
问题 This post discusses some issues with the proxy model for parameter passing in Rcpp. However, when I implemented this function: // [[Rcpp::export]] void test_size(NumericVector test){ NumericVector test2(test); NumericVector test3 = NumericVector::create(1,1,1,1,1); test2 = test3; Rf_PrintValue(test); } We get: > temp = c(2,2,2,2) > test_size(temp) [1] 2 2 2 2 So the problem is that the previous post and this book say that in this case test2 should be a pointer to the underlying SEXP object

Why do I need to run find_rtools() before has_devel() = TRUE?

风格不统一 提交于 2019-12-12 02:27:52
问题 I try to follow the guide in http://adv-r.had.co.nz/Rcpp.html to understand Rcpp but I always need to run devtools::find_rtools() before any Rcpp function works: If I do library(devtools) library(Rcpp) has_devel() # Error: Command failed(1) # Example from http://adv-r.had.co.nz/Rcpp.html add <- cppFunction('int add(int x, int y, int z) { int sum = x + y + z; return sum; }') I get an error and Rstudio prompts me to install additional build tools (but nothing happens when I say yes). It looks

Getting g++ error when installing R code from source

人盡茶涼 提交于 2019-12-12 01:42:09
问题 I've downloaded Rcpp from CRAN and unzipeed it and attempted to build it. When I try to use R CMD INSTALL . in the directory I get: cp: unknown option -- ) If I try to open up a session and use install.packages("Rcpp", type = "source"), I get the following error from g++ : *** arch - x64 g++ -m64 -I"C:/R/R-30~1.1/include" -DNDEBUG -I../inst/include/ -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c Date.cpp -o Date.o Date.cpp:1:0: sorry, unimplemented: 64-bit mode

Stack imbalance with RcppParallel

浪尽此生 提交于 2019-12-12 00:44:25
问题 I wrote the following code to train myself to use RcppParallel. It is just a toy example. // [[Rcpp::depends(RcppParallel)]] #include <Rcpp.h> #include <RcppParallel.h> #include <iostream> using namespace Rcpp; using namespace RcppParallel; struct Lapin : public Worker { // input pars const NumericVector input; const size_t dim; // outputs a matrix NumericMatrix output; // two constructors Lapin(const NumericVector input, const int dim) : input(input), dim(dim), output(NumericMatrix(dim,dim))

Optimization of an R loop taking 18 hours to run

人走茶凉 提交于 2019-12-12 00:15:20
问题 I've got an R code that works and does what I want but It takes a huge time to run. Here is an explanation of what the code does and the code itself. I've got a vector of 200000 line containing street adresses (String) : data. Example : > data[150000,] address "15 rue andre lalande residence marguerite yourcenar 91000 evry france" And I have a matrix of 131x2 string elements which are 5grams (part of word) and the ids of the bags of NGrams (example of a 5Grams bag : ["stack", "tacko", "ackov"

Rcpp package and Forecast package issues (old versions)

心已入冬 提交于 2019-12-11 19:16:37
问题 I have two linux machines with R version 3.0.0 I've installed the forecast package version 4.8 on both machines. Both machines have the same version of dependencies : >ip <- installed.packages() >ip[c("forecast","Rcpp","RcppArmadillo"),c("Package","Version")] Package Version forecast "forecast" "4.8" Rcpp "Rcpp" "0.10.2" RcppArmadillo "RcppArmadillo" "0.4.000.4" But when I run it on the other node I get the following error : >library(forecast) Error in loadNamespace(i, c(lib.loc, .libPaths())

Parallel Worker in namespace

浪尽此生 提交于 2019-12-11 18:49:33
问题 This example is a follow up example from this earlier post. I am trying to move the Parallel Worker to its own cpp file and and declare it in the header file. Calling 'mypackage' function within public worker The two errors are as follows: 1) variable type 'ExampleInternal::PARALLEL_WORKER' is an abstract class and in my non-reproducible example: 2) error: expected unqualified-id on the 'ExampleInternal::PARALLEL_WORKER{' line in the Parallel_worker.cpp file. Right now the code looks like

RInside call with arguments from R

眉间皱痕 提交于 2019-12-11 18:35:40
问题 I am trying to pass arguments to an exe file that includes RInside , and that is compiled using make . By taking this code inspired from here. #include <RInside.h> int main(int argc, char *argv[]) { // define two vectors in C++ std::vector<double> x({1.23, 2.34, 3.45}); std::vector<double> y({2.34, 3.45, 1.23}); // start R RInside R(argc, argv); // define a function in R R.parseEvalQ("rtest <- function(x, y) {x + y}"); // transfer the vectors to R R["x"] = x; R["y"] = y; // call the function

r aborted when using rcpp

旧城冷巷雨未停 提交于 2019-12-11 18:31:16
问题 I am writing some code, and when running, it aborted. The r version is 3.5.1. I think there is something wrong with my rcpp code, but I can't find it. It just shows R session aborted. ################I don't think there is anything wrong in this part. #include <Rcpp.h> Rcpp::LogicalVector logical_index(Rcpp::IntegerVector idx, R_xlen_t n) { bool invert = false; Rcpp::LogicalVector result(n, false); for (R_xlen_t i = 0; i < idx.size(); i++) { if (!invert && idx[i] < 0) invert = true; result

Double integral in RcppNumerical

烂漫一生 提交于 2019-12-11 17:45:24
问题 I have to calculate the double integral of the function: > DIntegral <- function(x,y){res <- pnorm(x,1,0.1) * dexp(y-2,1.2) return(res) } The upper limit for x and y are: 10 and Infinity respectively. The lower limit for x and y are: 1 and 2 respectively. How can I do this double integration in RcppNumerical ? For one dimensional integration my C++ file looks like: // [[Rcpp::depends(RcppEigen)]] // [[Rcpp::depends(RcppNumerical)]] #include <RcppNumerical.h> using namespace Numer; class PDF: