rcpp

Creating a progress update by replacing output in the R console from C/C++

六月ゝ 毕业季﹏ 提交于 2021-02-16 21:05:03
问题 Is it possible to overwrite R console output with the C/C++ print functions for R? Rcpp::sourceCpp( code = ' #include <Rcpp.h> // [[Rcpp::export]] void print_test() { for(int i = 0; i < 10; i++) { std::stringstream strs; strs << "number: " << i; std::string temp_str = strs.str(); char const* char_type = temp_str.c_str(); REprintf(char_type); } }' ) print_test() The output of this function is number: 0number: 1number: 2number: 3number: 4number: 5number: 6number: 7number: 8number: 9 but I want

Error in dyn.load(dllfile) — problem with building a package linking to Rcpp

江枫思渺然 提交于 2021-02-11 15:40:09
问题 My package will not install, either on my machine or on travis-ci.org. The only update from the version on CRAN is that I added a vignette. I have been following the examples of Rcpp - package and R-packages; compiled code. The error is related to these prior questions but not a duplicate. Q40922814 -- problem here was the use of both C and C++ code. I only use C++ code Q36952571 -- I'm on Mac OS, so no access to ldconfig , though perhaps my problem is related. Error: from the package

Error in dyn.load(dllfile) — problem with building a package linking to Rcpp

拥有回忆 提交于 2021-02-11 15:38:35
问题 My package will not install, either on my machine or on travis-ci.org. The only update from the version on CRAN is that I added a vignette. I have been following the examples of Rcpp - package and R-packages; compiled code. The error is related to these prior questions but not a duplicate. Q40922814 -- problem here was the use of both C and C++ code. I only use C++ code Q36952571 -- I'm on Mac OS, so no access to ldconfig , though perhaps my problem is related. Error: from the package

Error exposing c++ class method with reference parameter using Rcpp modules

六眼飞鱼酱① 提交于 2021-02-10 08:36:41
问题 My goal is to build a dataset class and a model class, and expose both of them to R. The model class has a train() method that takes a reference to a dataset instance, and this seems to be at the root of my issue. Here's what this looks like //glue.cpp #include <Rcpp.h> class MyData { public: MyData() = default; }; class MyModel { public: MyModel() = default; void train(const MyData& data) { Rcpp::Rcout << "training model... "; }; }; // Expose MyData RCPP_MODULE(MyData){ Rcpp::class_<MyData>(

return NA via RCpp

a 夏天 提交于 2021-02-10 04:37:08
问题 Newbie RCpp question here: how can I make a NumericVector return NA to R? For example, suppose I have a RCpp code that assigns NA to the first element of a vector. // [[RCpp::export]] NumericVector myFunc(NumericVector x) { NumericVector y=clone(x); y[0]=NA; // <----- what's the right expression here? return y; } 回答1: The canonical way to get the correct NA for a given vector type ( NumericVector , IntegerVector , ...) is to use the static get_na method. Something like: y[0] = NumericVector:

Adding column to Rcpp::DataFrame is falling back to list

故事扮演 提交于 2021-02-09 06:48:29
问题 When I add a column to a dataframe using Rcpp it ceases to be rendered as a dataframe once returned. I'm trying to stay as close to the original examples of adding a column as possible, but I get a list regardless of how I mutate it. As you can see below, I'm losing the class and some important attributes on the object when I add a column either via assigning to a new key or using push_back() . Runnable reprex here, or output copied below fun <- Rcpp::cppFunction(' List DataFrameExample() {

Error install RcppArmadillo on macOS Catalina [duplicate]

岁酱吖の 提交于 2021-02-08 11:10:38
问题 This question already has answers here : Cannot compile R packages with c++ code after updating to macOS Catalina (2 answers) Closed 1 year ago . I followed the steps in R Compiler Tools for Rcpp on macOS (for R 3.6.x), but an error occurs when I try to install RcppArmadillo . I don't have Xcode.app install, and prefer to use the command line tools instead. The answers posted here didn't help :( * installing *source* package ‘RcppArmadillo’ ... ** package ‘RcppArmadillo’ successfully unpacked

Error install RcppArmadillo on macOS Catalina [duplicate]

。_饼干妹妹 提交于 2021-02-08 11:06:08
问题 This question already has answers here : Cannot compile R packages with c++ code after updating to macOS Catalina (2 answers) Closed 1 year ago . I followed the steps in R Compiler Tools for Rcpp on macOS (for R 3.6.x), but an error occurs when I try to install RcppArmadillo . I don't have Xcode.app install, and prefer to use the command line tools instead. The answers posted here didn't help :( * installing *source* package ‘RcppArmadillo’ ... ** package ‘RcppArmadillo’ successfully unpacked

Why does rasterToPoints generate an error on first call but not second?

筅森魡賤 提交于 2021-02-08 07:32:20
问题 I have some code that loops over a list of study IDs ( ids ) and turns them into separate polygons/spatial points. On the first execution of the loop it produces the following error: Error in (function (x) : attempt to apply non-function This is from the raster::rasterToPoints function. I've looked at the examples in the help section for this function and passing fun=NULL seems to be an acceptable method (filters out all NA values). All the values are equal to 1 anyways so I tried passing a

Why does rasterToPoints generate an error on first call but not second?

两盒软妹~` 提交于 2021-02-08 07:32:09
问题 I have some code that loops over a list of study IDs ( ids ) and turns them into separate polygons/spatial points. On the first execution of the loop it produces the following error: Error in (function (x) : attempt to apply non-function This is from the raster::rasterToPoints function. I've looked at the examples in the help section for this function and passing fun=NULL seems to be an acceptable method (filters out all NA values). All the values are equal to 1 anyways so I tried passing a