Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using header (.h) files with cpp files in an R Package with Rcpp [duplicate]

Tags:

c++

r

rcpp

Possible Duplicate:
Using 3rd party header files with Rcpp

Note: This is a continuation of a discussion started here: Using 3rd party header files with Rcpp. However, the question is different enough that I thought I would pose it as its own question.

I have a header file called coolStuff.h that contains a function awesomeSauce(arg1) that I would like to call in the cpp files that are in my R package.

Package Structure:

  • packageName

    • DESCRIPTION
    • [man]

    • NAMESPACE

    • R
      • someRscript.R
    • src
      • theCppFile.cpp
      • otherCppFile.cpp

The Code for theCppFile.cpp:

`#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
double someFunctionCpp(double someInput){

 double someOutput = awesomeSauce(someInput);

return someOutput;`

1) Where should I place coolStuff.h in the package directory structure so that when the package is built, and the cpp files are compiled, the code from coolStuff.h will be included.

2) How should I call this file in the coolStuff.h?

3) Similarly, if I want to call otherCppFile.cpp in theCppFile.cpp where do

Thanks again for your help. I learned a lot from the last conversation. If there is standard documentation for some of this somewhere I'll be happy to RTFM, just point me in the right direction.

like image 376
politicalEconomist Avatar asked Oct 06 '22 09:10

politicalEconomist


1 Answers

There is an entire vignette devoted to building a package with Rcpp and yes, you should look at it.

Rcpp attributes are indeed fantastic for quick and simple things, but even they rely on packages: you couldn't do their Depends: on, say, RcppArmadillo if it weren't for the inline plugin provided by the RcppArmadillo package.

So in short: yes, do read the fine manual and/or look at (currently) 95 packages on CRAN that use Rcpp and Depends on it.

Edit: There is one possible short-cut here: if coolStuff.h is just a header (so no linking to external libraries) you can get by using it in the same directory as your source. That helps with quick sourceCpp() exploration. But to to a package you still need to do extra steps, but even some of those have been automated---see the Rcpp attributes vignette.

Edit 2: I just re-read your previous question. This new question makes no sense and adds nothing. Did you read and understand what we told you last time?

like image 162
Dirk Eddelbuettel Avatar answered Oct 10 '22 03:10

Dirk Eddelbuettel