Building packages with Rcpp, Attributes not handled correctly

Scott Ritchie

I've been playing around with setting up an R package which aims to make use of Rcpp in RStudio, but I'm struggling to get things to work properly with Rcpp Attributes.

My understanding of how this works is fairly tenuous, but my understanding is as follows:

  1. In the source C++ files, you can add Rcpp Attributes, for example the tag // [[Rcpp::export]] marks a C++ function for exporting, making it available for R.
  2. When you do Build the package, Rcpp then generates the appropriate C++ code in the file RcppExports.cpp, and wrapper functions in the R source file RcppExports.R.

This doesn't seem to be working properly (as I expect) when I build my package. Roxygen isn't playing nicely with this when generating the NAMESPACE file (so i've disabled that). The tag // [[Rcpp::export]] seems to just mark the function for exporting to R, rather than also marking a function for being exported to the package Namespace.

More importantly, the Rcpp Attribute tag // [[Rcpp::depends()]] isn't being handled correctly. If I copy the code here into a new source file, and rebuild my package, gcc throws errors on the RcppExports.cpp file saying that the BigMatrix identifier is undeclared indicating that the attribute tage // [[Rcpp::depends(bigmemory)]] isn't being handled correctly.

Since multiple things aren't working as I would expect, What am I missing in my understanding of Rcpp Attribute tags?

Romain Francois

This is an issue with the RcppExports.cpp file that is generated. At the moment, there is no way to teach it to include header files from somewhere else, so it just does not include bigmemory/MatrixAccessor.hpp.

A workaround is to do this:

#include <Rcpp.h>
#include <bigmemory/MatrixAccessor.hpp>

Rcpp::NumericVector BigColSums(Rcpp::XPtr<BigMatrix> pBigMat) {

    // Create the matrix accessor so we can get at the elements of the matrix.
    MatrixAccessor<double> ma(*pBigMat);

    // Create the vector we'll store the column sums in.
    Rcpp::NumericVector colSums(pBigMat->ncol());
    for (size_t i=0; i < pBigMat->ncol(); ++i)
        colSums[i] = std::accumulate(ma[i], ma[i]+pBigMat->nrow(), 0.0);
    return colSums;
}

// [[Rcpp::export]]
Rcpp::NumericVector BigColSums( SEXP pBigMat ){
    return  BigColSums( Rcpp::XPtr<BigMatrix>( pBigMat) ) ;   
}

So that you capture the type in your .cpp file and RcppExports.cpp only has to know about SEXP.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Rcpp openmp plugin in building package

From Dev

Building toy package linking to Rcpp

From Dev

Rcpp openmp plugin in building package

From Dev

Directive not getting attributes correctly

From Dev

How should an accumulator in a Python clock be handled correctly?

From Dev

Ajax response is null on PHP correctly handled data

From Dev

Building a tiny R package with CUDA and Rcpp

From Dev

Rcpp: error occured building shared library

From Dev

changing R packages' exportPattern to hide Rcpp functions

From Dev

changing R packages' exportPattern to hide Rcpp functions

From Dev

Building R packages with Packrat and AppVeyor

From Dev

Building Python Extension Packages for Launchpad

From Dev

No speex packages for freeswitch building on Ubuntu

From Dev

Building packages from launchpad respository

From Dev

How to correctly change a list of a ListMatrix in rcpp in R

From Dev

Not Building jQuery ajax data correctly

From Dev

Ruby class attributes not querying correctly

From Dev

XML wont parse attributes correctly

From Dev

NuGet Packages claiming to not be correctly installed

From Dev

Timer callback raised every 24 hours - is DST handled correctly?

From Dev

react-router replace function not being handled correctly

From Dev

Why is my unicode string not being handled (printed/copied) correctly?

From Dev

Have I handled the errors correctly with this json_encode()?

From Dev

EWS soap request with Chinese content cannot be handled correctly by Exchange server

From Dev

Why is my unicode string not being handled (printed/copied) correctly?

From Dev

Negative short in Java to uint16_t in NDK not handled correctly?

From Dev

85 bit encoded strings are not being handled correctly on being decoded in python

From Dev

Building R package with C++11 & Rcpp on Windows

From Dev

Dealing with decorated external binaries when building a package with Rcpp

Related Related

  1. 1

    Rcpp openmp plugin in building package

  2. 2

    Building toy package linking to Rcpp

  3. 3

    Rcpp openmp plugin in building package

  4. 4

    Directive not getting attributes correctly

  5. 5

    How should an accumulator in a Python clock be handled correctly?

  6. 6

    Ajax response is null on PHP correctly handled data

  7. 7

    Building a tiny R package with CUDA and Rcpp

  8. 8

    Rcpp: error occured building shared library

  9. 9

    changing R packages' exportPattern to hide Rcpp functions

  10. 10

    changing R packages' exportPattern to hide Rcpp functions

  11. 11

    Building R packages with Packrat and AppVeyor

  12. 12

    Building Python Extension Packages for Launchpad

  13. 13

    No speex packages for freeswitch building on Ubuntu

  14. 14

    Building packages from launchpad respository

  15. 15

    How to correctly change a list of a ListMatrix in rcpp in R

  16. 16

    Not Building jQuery ajax data correctly

  17. 17

    Ruby class attributes not querying correctly

  18. 18

    XML wont parse attributes correctly

  19. 19

    NuGet Packages claiming to not be correctly installed

  20. 20

    Timer callback raised every 24 hours - is DST handled correctly?

  21. 21

    react-router replace function not being handled correctly

  22. 22

    Why is my unicode string not being handled (printed/copied) correctly?

  23. 23

    Have I handled the errors correctly with this json_encode()?

  24. 24

    EWS soap request with Chinese content cannot be handled correctly by Exchange server

  25. 25

    Why is my unicode string not being handled (printed/copied) correctly?

  26. 26

    Negative short in Java to uint16_t in NDK not handled correctly?

  27. 27

    85 bit encoded strings are not being handled correctly on being decoded in python

  28. 28

    Building R package with C++11 & Rcpp on Windows

  29. 29

    Dealing with decorated external binaries when building a package with Rcpp

HotTag

Archive