use_tmb: Add 'TMB' functionality to an existing package.

View source: R/use_tmb.R

use_tmbR Documentation

Add TMB functionality to an existing package.

Description

Add TMB functionality to an existing package.

Usage

use_tmb()

Details

Adds the following to the package:

  • src/TMB/compile.R: runs the C++ compiler on TMB model files (see export_models).

  • src/Makevars[.win]: ensures that TMB compilation does not affect that of other source files in src.

  • src/init_dummy_file.cpp: needed to set R_registerRoutines if the package contains no other source code apart from what's in src/TMB.

  • Imports: TMB and LinkingTo: TMB are added to the package's DESCRIPTION.

  • An optional file R/pkgname-package.R with roxygen2 NAMESPACE directives, if such a file does not exist. Otherwise, prints instructions as to how the NAMESPACE must be modified (see below).

Because of how TMB source files are compiled, at present the package must create two shared object (.so, .dll) files: pkgname_TMBExports.so for the TMB models, and pkgname.so for the usual package source code. In the NAMESPACE file, it is imperative that the latter be 'useDynLib'ed before the former. The fail-safe roxygen2 instruction for this is

#' @rawNamespace useDynLib(pkgname, .registration = TRUE); useDynLib(pkgname_TMBExports)

Value

Nothing; called for its side effects.

See Also

export_models for details on adding TMB model files after running use_tmb.


mlysy/TMBtools documentation built on April 1, 2022, 6:18 p.m.