Skip to content

Commit

Permalink
Expand libraries vignette with PACKAGE_types.h
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jan 25, 2025
1 parent 5beadc1 commit bbdc9f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
27 changes: 18 additions & 9 deletions vignettes/rmd/Rcpp-libraries.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,24 @@ it.

Given a basic package with C++ support, we can now turn to integrating the external
package. This complexity of this step can, as alluded to earlier, vary from very easy to
very complex. Simple cases include just depending on library headers which can either
be copied to the package, or be provided by another package such as \pkg{BH}
\citep{CRAN:BH}. It may also be a dependency on a fairly standard library available on
most if not all systems. The graphics formats bmp, jpeg or png may be example; text
formats like JSON or XML are another. One difficulty, though, may be that _run-time_
support does not always guarantee _compile-time_ support. In these cases, a `-dev` or
`-devel` package may need to be installed.

In the concrete case of Corels, we
very complex. Simple cases include just depending on library headers which can either be
copied to the package, or be provided by another package such as \pkg{BH} \citep{CRAN:BH}
or \pkg{AsioHeaders} \citep{CRAN:AsioHeaders} or many other examples.

One aspect worth noting is that if you include a type in your function interface it will
also be part of the generated \code{RcppExports.cpp}. In this case adding a file
\code{PACKAGE\_types.h} (where \code{PACKAGE} is to be replaced with the name of your
package) containing the required \code{\#include} statement for the type(s) will permit
compilation; see the 'Rcpp Attributes' vignette for details \citep{CRAN:Rcpp:Attributes}.

It may also be a dependency on a fairly standard library available on most if
not all systems. The graphics formats bmp, jpeg or png may be example; text
formats like JSON or XML are another. One difficulty, though, may be that
_run-time_ support does not always guarantee _compile-time_ support. In these
cases, a `-dev` or `-devel` package may need to be installed.

Here, we use a third approach and copy files. Discussing the two other means
fully is beyond the scope of this shorter note. So in the concrete case of Corels, we

- copied all existing C++ source and header files over into the `src/` directory;
- renamed all header files from `*.hh` to `*.h` to comply with an R preference;
Expand Down
8 changes: 8 additions & 0 deletions vignettes/rmd/Rcpp.bib
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ @Manual{CRAN:anytime
url = CRAN # "package=anytime"
}

@Manual{CRAN:AsioHeaders,
title = {'Asio' C++ Header Files},
author = {Dirk Eddelbuettel},
year = {2024},
note = {R package version 1.22.1},
url = CRAN # "package=AsioHeaders"
}

@Manual{CRAN:BH,
title = {BH: Boost C++ Header Files},
author = {Dirk Eddelbuettel and John W. Emerson and Michael
Expand Down

0 comments on commit bbdc9f5

Please sign in to comment.