-1

I have a Cpp function that is called inside an R function using Rcpp packgae. The R function accepts an inputDataFrame and uses the Cpp function (also accepts a DataFrame) to calculate drug amounts (A1) as a function of time. R then returns the inputDataFrame with added column for the calculated amounts A1.

I want to documnet the R functions (rather than the Cpp functions) using roxygen2 package in RStudio. However, when I used roxygen2 comments (as below), it did not generate the *.RD files and help pages the way you expected to do upon building the model. Please note that I have no trouble using roxygen2 when my package contains only R functions. In the latter case *.RD files and help pages are generated automatically as expected.

Any hints on how to do that?

Amer
  • 2,131
  • 3
  • 23
  • 38
  • Your `@description` etc. annotations are already roxygen comments. Use `devtools::document()` to create a documentation from that. See http://r-pkgs.had.co.nz/man.html#man-workflow for more details. – Patrick Roocks Apr 26 '16 at 06:00
  • Yep. Thank you. But when I run an example using the packge `pharm`, I end up with this error: ` Error in .Call("pharm_OneCompIVbolusCpp", PACKAGE = "pharm", inputFrame) : "pharm_OneCompIVbolusCpp" not available for .Call() for package "pharm" ` – Amer Apr 26 '16 at 06:29
  • Is there a way to make the Cpp function available to the R-function? – Amer Apr 26 '16 at 06:29
  • Possible duplicate of [C++ function not available](http://stackoverflow.com/questions/36605955/c-function-not-available) – coatless Apr 26 '16 at 06:40

1 Answers1

6

Of course you can do that.

First create a package, either via the helper feature in RStudio or by calling Rcpp.package.skeleton().

Second create a roxygen block in your C++ source file. See a million examples on GitHub as eg this recent example one of mine.

Third tell Rcpp to create the C++ -> R bindings: call compileAttributes(). RStudio would do this for you. Now you have roxygen markup in R (as eg seen here).

Fourth have Roxygen process the markup. You can enable this in RStudio, I just call (a helper script calling) roxygen2::roxygenize(".", roclets="rd"). This create the manual page

And now you have a package with an R function calling a C++ function.

And all that has been explained for years in the corresponding Rcpp Attributes vignette.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725