rcpp

Rcpp warning: Call to 'exp' is ambiguous

我与影子孤独终老i 提交于 2021-02-05 08:19:06
问题 I am writing a Rcpp code as below: // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::depends(BH)]] // [[Rcpp::plugins(cpp11)]] #include <RcppArmadillo.h> #include <boost/random.hpp> #include <boost/random/uniform_real_distribution.hpp> #include <math.h> using namespace Rcpp; using namespace std; // [[Rcpp::export]] double ks(const double k, const double alpha, const double mag, const double M0){ double ksres; ksres= k* std::exp ( alpha*(mag-M0) ); return(ksres); } . But it shows that "Call to

R unable to load dplyr

时光总嘲笑我的痴心妄想 提交于 2021-02-05 08:11:50
问题 I'm running from Ubuntu 16, using R version 3.4.1. I have dplyr installed and can load it when either I am running from RStudio or when I sudo into R from the terminal. However, if I run R without root permission, I cannot load dplyr due to the following error: Error: package or namespace load failed for ‘dplyr’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '<user-directory>/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs/Rcpp.so': <user-directory>/anaconda3/lib/R/bin

Using SuperLU sparse solver with RcppArmadillo

混江龙づ霸主 提交于 2021-02-05 04:49:56
问题 I am trying to use the SparseLU solver from armadillo (http://arma.sourceforge.net/docs.html#spsolve) through RcppArmadillo: #define ARMA_USE_SUPERLU // [Rcpp::depends(RcppArmadillo)] #include <RcppArmadillo.h> // [[Rcpp::export]] arma::vec sp_solver(arma::sp_mat K, arma::vec x) { arma::superlu_opts opts; opts.symmetric = true; arma::vec res; arma::spsolve(res, K, x, "superlu", opts); return res; } /*** R library(Matrix) K <- sparseMatrix(i = c(1, 2, 1), j = c(1, 2, 2), x = c(1, 1, 0.5),

Using SuperLU sparse solver with RcppArmadillo

戏子无情 提交于 2021-02-05 04:49:45
问题 I am trying to use the SparseLU solver from armadillo (http://arma.sourceforge.net/docs.html#spsolve) through RcppArmadillo: #define ARMA_USE_SUPERLU // [Rcpp::depends(RcppArmadillo)] #include <RcppArmadillo.h> // [[Rcpp::export]] arma::vec sp_solver(arma::sp_mat K, arma::vec x) { arma::superlu_opts opts; opts.symmetric = true; arma::vec res; arma::spsolve(res, K, x, "superlu", opts); return res; } /*** R library(Matrix) K <- sparseMatrix(i = c(1, 2, 1), j = c(1, 2, 2), x = c(1, 1, 0.5),

Importing an Rcpp header file in NAMESPACE within an R Package

China☆狼群 提交于 2021-01-29 17:26:54
问题 This is my first package in R , I already have working package but I would remove some rewriting function in cpp file, so I do an header file that work with single function. How can I put this header in package? Note that header.h and header.cpp are in src/ directory of package and the #include "header.h" is in the .cpp file where I use this function I tried to modify the NAMESPACE file with: import(myheader) But, when I do: R CMD INSTALL mypackage I receive this error: Error: package or

A simple RcppArmadillo index issue

岁酱吖の 提交于 2021-01-29 16:56:25
问题 I'm coding with RcppArmadillo and got stuck with a very basic question. Suppose I have a vector "v", and I want to take its first 10 elements, like in R: v[1:10] . Since 1:10 doesn't work in RcppArmadillo , I tried v.elem(seq_len(10)) , but it didn't work. Any hint? 回答1: Assuming you're taking about an arma::vec , this should work: #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] arma::vec f(const arma::vec & v, int first, int last) { arma::vec out = v.subvec

Error creating R package: Error in dyn.load(file, DLLpath = DLLpath, …)

夙愿已清 提交于 2021-01-28 08:31:13
问题 I am creating an R package called CVOC. It includes C++ code and uses high precision arithmetic from the C library gmp. The package is to be created by the following steps: 1) using Rcpp::Rcpp.package.skeleton to create the package skeleton. 2) copying the required files, such as DESCRIPTION, NAMESPACE, Makevars, etc. , into the correct folders 3) creating the .Rd documentation files using roxygen2::roxygenise() 4) checking the R-package using R CMD check 5) building the R-package using R CMD

sample in Rcpp Armadillo

心不动则不痛 提交于 2021-01-27 21:30:25
问题 I am currently struggeling with the sample() command provided in RcppArmadillo . When I try to run the code below I get the error no matching function for call to sample and I already add the extra Rcpp:: namespace in front since this worked out well in another post. I also tried several other container classes, but I am always stuck with this error. Below is some code, which produces the error. Any help would be greatly appreciated :) #include <RcppArmadillo.h> // [[Rcpp::depends

Compiling Rcpp functions using ClusterEvalQ

 ̄綄美尐妖づ 提交于 2021-01-27 14:43:24
问题 I am working on a project that requires parallel processing in R, and I am new to the doparallel package. What I would like to do is use a parallelized foreach loop. Due to the nature of the problem, this foreach loop will need to be executed many times. The problem I am having is that I use cppfunction and cfunction within the loop. The current work around is to call clusterEvalQ() for the cluster and to compile the relevant functions. However, this is extremely slow (~10 seconds for 4 cores

Rcpp: How to ensure deep copy of a NumericMatrix?

六月ゝ 毕业季﹏ 提交于 2021-01-27 06:22:06
问题 Suppose, I have a Rcpp::NumericMatrix A. I want to make an identical copy (not pointer copy) of A into another Rcpp::NumericMatrix B. Is this the correct way of doing this job? Rcpp::NumericMatrix B(Rcpp::clone(A)); Also what is the difference between the above line and the following: Rcpp::NumericMatrix B(A); 来源: https://stackoverflow.com/questions/31015321/rcpp-how-to-ensure-deep-copy-of-a-numericmatrix