rcpp

Rcpp - sourceCpp - undefined symbol

这一生的挚爱 提交于 2020-01-19 04:11:05
问题 I'm using Rcpp to get self-written C++ into R. I have the 3 follwing C++ files header.h #include <Rcpp.h> int x(); def.cpp #include <Rcpp.h> #include "header.h" // [[Rcpp::export]] int x() { return 0; } call.cpp #include <Rcpp.h> #include "header.h" // [[Rcpp::export]] int callx(){ return x(); } After compiling successfully I can call the function callx() as well as x() from R R> callx() [1] 0 R> x() [1] 0 But when I try to source the file call.cpp using cppSource I get this error > Rcpp:

Code using RcppArmadillo compiles when running R from terminal but not rstudio-server

只愿长相守 提交于 2020-01-17 04:43:47
问题 I'm trying to get some c++ code to compile using sourceCpp and RcppArmadillo. I'm using R 3.3.3 on Ubuntu, Rcpp 0.12.10 and RcppArmadillo 0.7.800.2.0. The file, armatest.cpp, is totally stripped down. // [[Rcpp::depends(RcppArmadillo)]] #include <RcppArmadillo.h> using namespace arma; using namespace Rcpp; int one() { return 1; } When I attempt to compile this from within Rstudio server, I get the following compilation error: > Rcpp::sourceCpp("armatest.cpp", verbose = TRUE, rebuild=TRUE)

using `XPtr` to create pointer to a user defined function in Rcpp

耗尽温柔 提交于 2020-01-16 09:59:07
问题 --------- Adding a summary of the problem --------------------------------- I want to create a externalpointer for a user defined function which can be passed to the another function. The user will provide function name as a string, my question is how can I convert that into a function pointer, after checking that the user provided string (say fstr ) matches with the name of the function that was created by the user, i.e. if (fstr == "<USER_DEFINED_FUNCTION_NAME>") XPtr<funcPtr> fun(new

Returning bunch of matrices using RCPP in C++ in an efficient way using a list

落爺英雄遲暮 提交于 2020-01-16 05:19:06
问题 I am trying to return a bunch of matrices using RCPP. My code below is extremely inefficient. I would like to know if the following code can be efficient. #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] Rcpp::List hello( const arma::rowvec& g, const int& n, const int& p, const arma::mat& S, const arma::mat& zc, const arma::rowvec& dl){ Rcpp::List ht(n); for(int t=0; t < n;++t){ arma::mat hhat(p,n); hhat.fill(0.0); for(int i = 0;i < n; ++i){ arma::mat h(p,1);

How to use Rcpp with TDM-gcc 4.8.1?

与世无争的帅哥 提交于 2020-01-15 08:57:13
问题 I'm using R 3.0.2 under Windows 7 (32bit) and has TDM-GCC-32 (gcc (tdm-2) 4.8.1) in the path. When I try to use cppFunction, I get some error: library(inline) library(Rcpp) src <- ' SEXP hellofun(){ std::vector<std::string> s; s.push_back("hello"); s.push_back("world"); return Rcpp::wrap(s); }' hello_fun <- cppFunction(src) Error message: Error in inDL(x, as.logical(local), as.logical(now), ...) (from file1c8c8c929f5.cpp.R#1) : unable to load shared object 'C:/Users/ssss11/AppData/Local/Temp

Rcpp, creating a dataframe with a vector of long long

走远了吗. 提交于 2020-01-15 05:32:46
问题 I have a series of vectors which I am adding into a DataFrame object to return to R. The problem comes when I try and add a vector with long long elements. // [[Rcpp::export]] DataFrame test() { std::vector<long long> x; return DataFrame::create(Named("x") = x); } The error returned is g++ -m64 -I"C:/R/R-30~1.1/include" -DNDEBUG -I"C:/R/R-3.0.1/library/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c quotes.cpp -o quotes.o In file included from C:/R/R

Parallelize function taking external pointers (XPtr)

最后都变了- 提交于 2020-01-14 13:55:43
问题 This question is neither a duplicate of this one nor of this one, which were about functions returning external pointers. Here's the issue. The Rcpp code hereafter defines two functions, one which creates an XPtr, and another one which can work on the XPtr. #include <Rcpp.h> using namespace Rcpp; //[[Rcpp::export]] SEXP f(int n) { std::vector<int> * v = new std::vector<int>; for(int i = 0; i < n; i++) v->push_back(i); XPtr< std::vector<int> > p(v, true); return p; } //[[Rcpp::export]] int g

R memory leak using C external pointers

走远了吗. 提交于 2020-01-14 13:06:13
问题 I'm trying to use external pointers in a package, but I ran into an issue where it seemed like the finalizer was not being called and memory leaked. Below is an extremely contrived example of the issue: #include <Rcpp.h> using namespace Rcpp; void finalize(SEXP xp){ delete static_cast< std::vector<double> *>(R_ExternalPtrAddr(xp)); } // [[Rcpp::export]] SEXP ext_ref_ex() { std::vector<double> * x = new std::vector<double>(1000000); SEXP xp = PROTECT(R_MakeExternalPtr(x, R_NilValue, R_NilValue

function leading to check error in automatically generated RcppExports.R

守給你的承諾、 提交于 2020-01-13 19:03:30
问题 I am using Rcpp 0.12.11 and R 3.4.0. When I upgraded Rcpp to 0.12.11, the automatically generated R file RcppExports.R by the Rcpp::compileAttributes started to give me slightly different function calls run_graph_match <- function(A, B, algorithm_params) { # Rcpp 0.12.10 .Call('RGraphM_run_graph_match', PACKAGE = 'RGraphM', A, B, algorithm_params) # Rcpp 0.12.11 .Call(RGraphM_run_graph_match, A, B, algorithm_params) } Is there an easy way to explain the reason behind the change? The latter

Difference between value and reference args in Rcpp [duplicate]

可紊 提交于 2020-01-13 11:08:08
问题 This question already has an answer here : Rcpp pass by reference vs. by value (1 answer) Closed 2 years ago . Consider these 2 functions: library(Rcpp) cppFunction("NumericVector func1(NumericVector &x) { for (int i = 0; i < x.length(); i++) x[i] = x[i] * 2; return x; }") cppFunction("NumericVector func2(NumericVector x) // no & { for (int i = 0; i < x.length(); i++) x[i] = x[i] * 2; return x; }") The only difference is that func1 takes x as a reference parameter, whereas func2 takes it as a