rcpp

How can I use qnorm on Rcpp?

痴心易碎 提交于 2019-12-18 08:48:07
问题 require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp") error: no matching function for call to ‘qnorm5(double, int, int)’ require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );' ,plugin="Rcpp") error: no matching function for call to ‘qnorm5(double, double, double, int, int)’ require(inline) code <-' double a = qnorm(0.95, 0.0, 1.0); return Rcpp::wrap( a ); ' func <- cxxfunction(, code ,plugin="Rcpp") func() error:

Rcpp Error with Xcode 5.0 and OSX 10.8.5 and R 3.0.2

断了今生、忘了曾经 提交于 2019-12-18 06:51:21
问题 I'm just trying to get Rcpp up and running on my Mac, but am struggling. I've installed the Command Line Tools. I've installed the Rcpp and inline packages. I try to run the following script in R, and get the following error. fx <- cxxfunction(signature( x = "numeric" ), 'NumericVector xx(x); return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));', plugin = "Rcpp",verbose=TRUE) Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s)

Rcpp::compileAttributes() Error

和自甴很熟 提交于 2019-12-18 06:09:50
问题 I am trying to compile a small package that I've made. This package uses Rcpp and RcppArmadillo. Everything was working well until I updated my mac to Sierra (version 10.12.5). I have now the following error message when building the package from Rstudio (version 1.0.143): Error in Rcpp::compileAttributes() : Evaluation error: no native symbols were extracted. Calls: source ... withVisible -> eval -> eval -> <Anonymous> -> .Call Execution halted Any idea what this is and how it can be fixed?

S4 object with a pointer to a C struct

狂风中的少年 提交于 2019-12-18 05:16:06
问题 I have a third-party C library I am using to write an R extension. I am required to create a few structs defined in the library (and initialize them) I need to maintain them as part of an S4 object (think of these structs as defining to state of a computation, to destroy them would be to destroy all remaining computation and the results of all that has been already computed). I am thinking of creating a S4 object to hold pointers these structs as void* pointers but it is not at all clear how

RcppArmadillo Compile Errors on OS X Mavericks

六月ゝ 毕业季﹏ 提交于 2019-12-18 04:59:07
问题 This is a follow-up to the question at Element-Wise Matrix Multiplication in Rcpp I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below -- > cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo") ld: library not found for -lgfortran clang: error: linker command failed with

Pass a c++ object as a pointer an reuse in another function in Rcpp

不问归期 提交于 2019-12-18 04:09:42
问题 Suppose a I have the following 2 functions in C++: // [[Rcpp::export]] SEXP foo() { int a = 1; Rcpp::XPtr<int> ptr(&a, true); return ptr; } // [[Rcpp::export]] int bar(SEXP a){ Rcpp::XPtr<int> x(a); int b = *x; return b; } I want to be able to call something like the following in R. Of course, in this example I could return an int to R in foo , but in my original code, a is a somewhat complex data structure and I wan't to return only the pointer to this, so it can be reused by another C++

Why is this naive matrix multiplication faster than base R's?

浪尽此生 提交于 2019-12-17 23:33:48
问题 In R, matrix multiplication is very optimized, i.e. is really just a call to BLAS/LAPACK. However, I'm surprised this very naive C++ code for matrix-vector multiplication seems reliably 30% faster. library(Rcpp) # Simple C++ code for matrix multiplication mm_code = "NumericVector my_mm(NumericMatrix m, NumericVector v){ int nRow = m.rows(); int nCol = m.cols(); NumericVector ans(nRow); double v_j; for(int j = 0; j < nCol; j++){ v_j = v[j]; for(int i = 0; i < nRow; i++){ ans[i] += m(i,j) * v_j

Using 3rd party header files with Rcpp

99封情书 提交于 2019-12-17 21:41:32
问题 I have a header file called coolStuff.h that contains a function awesomeSauce(arg1) that I would like to use in my cpp source file. Directory Structure: RworkingDirectory sourceCpp theCppFile.cpp cppHeaders coolStuff.h The Code: #include <Rcpp.h> #include <cppHeaders/coolStuff.h> using namespace Rcpp; // [[Rcpp::export]] double someFunctionCpp(double someInput){ double someOutput = awesomeSauce(someInput); return someOutput; } I get the error: theCppFile.cpp:2:31: error: cppHeaders/coolStuff

Matrix Multiplication Using NumericMatrix and NumericVector in Rcpp

ぃ、小莉子 提交于 2019-12-17 20:25:09
问题 I am wondering is there a way of calculating matrix multiplication using NumericMatrix and NumericVector class. I am wondering if there is any simple way to help me avoid the following loop to conduct this calculation. I just want to calculate X%*%beta. // assume X and beta are initialized and X is of dimension (nsites, p), // beta is a NumericVector with p elements. for(int j = 0; j < nsites; j++) { temp = 0; for(int l = 0; l < p; l++) temp = temp + X(j,l) * beta[l]; } Thank you very much in

Installing RcppEigen on amazon ec2

ぐ巨炮叔叔 提交于 2019-12-17 19:42:31
问题 I tried to install RcppEigen on amazon EC2 (on a t1.micro to make sure It works) & ubuntu 13.04. I tried with both R version was 2.15.2 and 3.0, 32bit ubuntu and 64bit ubuntu. Any time I got the following: root@ip-10-224-4-239:/home/ubuntu# R CMD INSTALL RcppEigen_0.3.1.2.1.tar.gz * installing to library ‘/usr/local/lib/R/site-library’ * installing *source* package ‘RcppEigen’ ... ** package ‘RcppEigen’ successfully unpacked and MD5 sums checked ** libs g++ -I/usr/share/R/include -DNDEBUG -I"