5

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.

Community
  • 1
  • 1
politicalEconomist
  • 1,041
  • 1
  • 14
  • 19

1 Answers1

4

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?

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks Dirk I will take a look at that and see if I can make heads or tails of it. I have found that some of the Rcpp documentation assumes I know a lot more about C++ than I do, and for that matter a lot more about the deeper internals of R and Rcpp than I do. – politicalEconomist Jan 10 '13 at 23:02
  • It's complicated. We try our hardest to make some things easy, but we can do that for all things. You still need to read up on a few things, and package creation is among them. Or use the worked examples --- see eg the hint I just added to my answer. – Dirk Eddelbuettel Jan 10 '13 at 23:05
  • OK I guess this was not different enough to be its own question. I will continue on the original question. http://stackoverflow.com/questions/13995266/using-3rd-party-header-files-with-rcpp – politicalEconomist Jan 11 '13 at 05:53