rcpp

Rcpp: dynamically update a list

£可爱£侵袭症+ 提交于 2019-12-08 03:57:47
问题 I am seeking solutions to dynamically updating a list. #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] List Test(){ List L; List L1=List::create(12,45,22,44); L=Language("c",L,L1).eval();//update, add L1's elements on L's back. return L; } The above doesn't work since "List L;" makes L an empty list. However, if I write an additional function: List connectlist(List& a, List& b){ return Language("c",a,b).eval(); } and replace "L=Language("c",L,L1).eval();" with "connectlist(L,L1);"

Syncing Rcpp with external headers and libraries to build a batch geocoding package

被刻印的时光 ゝ 提交于 2019-12-08 03:32:54
问题 Good evening. GOAL: I am attempting to build a batch geocoding package based on the New York City Department of City Planning's Geosupport software using RCPP from within RStudio on a machine running Windows. Geosupport returns a lot of useful information besides coordinates including building identification number and census geographies. I think such a package has the potential to be very useful to researchers and community advocates working with NYC data. BACKGROUND: Geosupport is available

Compiling multiple source files in Rcpp

断了今生、忘了曾经 提交于 2019-12-08 03:26:00
问题 I have the following directory structure my_func - my_func_r.cpp - my_func.c - my_func.h - my_func_test.c - matrix/ - matrix.h - matrix.c The matrix directory contains some matrix structures in matrix.h and some initialisation, free, print etc. functions in matrix.c . The my_func.h file is something like #include <math.h> #include <stdio.h> #include <stdlib.h> #include "matrix/matrix.h" ... some structures and templates ... The my_func.c file is then #include "my_func.h" ... helper functions

Extract long[] from R object

◇◆丶佛笑我妖孽 提交于 2019-12-08 02:51:59
问题 I'm trying to make a wrapper for some C-based sparse-matrix-handling code (see previous question). In order to call the workhorse C function, I need to create a structure that looks like this: struct smat { long rows; long cols; long vals; /* Total non-zero entries. */ long *pointr; /* For each col (plus 1), index of first non-zero entry. */ long *rowind; /* For each nz entry, the row index. */ double *value; /* For each nz entry, the value. */ }; These correspond nicely to the slots in a

R package with c++ code failed installation, No DLL was created

为君一笑 提交于 2019-12-08 02:12:11
问题 I'm currently working on an R package which uses C++ code and includes external libraries (dlib, boost and an optimization library developed in the group). We're using Rcpp to integrate R and C++, but the problem is the package always fails to compile, and none of the similar questions I've found out there have worked for me. The report generated by R CMD check is: * installing *source* package 'IRTppExperimental' ... ** libs *** arch - i386 c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA

Converting element of 'const Rcpp::CharacterVector&' to 'std::string'

↘锁芯ラ 提交于 2019-12-08 01:57:07
问题 I am wondering if there is a Rcpp way to convert an element or iterator of const CharacterVector& to std::string . If I try the following code void as(const CharacterVector& src) { std::string glue; for(int i = 0;i < src.size();i++) { glue.assign(src[i]); } } a compiler-time error will occurred: no known conversion for argument 1 from ‘const type {aka SEXPREC* const}’ to ‘const char*’ So far, I use C API to do the conversion: glue.assign(CHAR(STRING_ELT(src.asSexp(), i))); My Rcpp version is

Rcpp and CULA: segmentation fault

浪子不回头ぞ 提交于 2019-12-07 23:58:08
问题 I extracted the relevant bits from the gputools R -package to run a QR decomposition on my GPU using Rcpp by dynamically loading a shared library that links to culatools . Everything runs smoothly in the terminal and R.app on my Mac. The results agree with R 's qr() function, but the problem is that a segmentation fault occurs on exiting R.app (the error does not occur when using the terminal): *** caught segfault *** address 0x10911b050, cause 'memory not mapped' I think I narrowed down the

Rcpp: Mac shows loading wheel and almost freeze

感情迁移 提交于 2019-12-07 23:15:34
问题 I created a R package which depends on Rcpp. A function in this package supposed to show printing statements at every n iterations. So I expect to see a new line on R console every few seconds. The odd thing is that when I run my function in R GUI, the cursor becomes a loading wheel and R "almost" freezes. The loading wheel disappear once after the computation is done. The minimal example of this situation is summarized as follow: library(inline) library(Rcpp) test <- cxxfunction( signature()

RcppModules: Manually build/expose C+ classes to R

孤者浪人 提交于 2019-12-07 21:34:04
问题 The goal is to wrap fairly large existing collection of C++ classes to be callable from R. The first approach is to manually define R Reference Classes and call into "SEXP-wrapped" entry points - and this works fine, no problems. Another approach that I'm currently evaluating is RcppModules. I can successfully use it with toy example within R - with Rcpp::SourceCPP . But have troubles with doing this manually. Example: //---example.cpp #include "Rcpp.h" using namespace Rcpp; class Example {

Column means 3d matrix (cube) Rcpp

断了今生、忘了曾经 提交于 2019-12-07 20:11:05
问题 I have a program in which I need to calculate repeatedly the column means of each slice of a cube X(nRow, nCol, nSlice) in Rcpp, with the resulting means forming a matrix M(nCol, nSlice) . The following code produced an error: #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; // [[Rcpp::export]] mat cubeMeans(arma::cube X){ int nSlice = X.n_slices; int nCol = X.n_cols; int nRow = X.n_rows; arma::vec Vtmp(nCol); arma::mat Mtmp(nRow, nCol