Create an odin model within an existing package.

odin_package(path_package)

Arguments

path_package

Path to the package root (the directory that contains DESCRIPTION)

Details

I am resisting the urge to actually create the package here. There are better options than I can come up with; for example devtools::create, pkgkitten::kitten, mason::mason, or creating DESCRIPTION files using desc. What is required here is that your package:

  • Lists odin in Imports:

  • Includes useDynLib(<your package name>) in NAMESPACE (possibly via a roxygen comment @useDynLib <your package name>

  • To avoid a NOTE in R CMD check, import something from odin in your namespace (e.g., importFrom("odin", "odin")s or roxygen @importFrom(odin, odin)

Point this function at the package root (the directory containing DESCRIPTION and it will write out files src/odin.c and odin.R. These files will be overwritten without warning by running this again.

Examples

path <- tempfile()
dir.create(path)

src <- system.file("examples/package", package = "odin", mustWork = TRUE)
file.copy(src, path, recursive = TRUE)
#> [1] TRUE
pkg <- file.path(path, "package")

# The package is minimal:
dir(pkg)
#> [1] "DESCRIPTION" "NAMESPACE"   "inst"       

# But contains odin files in inst/odin
dir(file.path(pkg, "inst/odin"))
#> [1] "lorenz.R"

# Compile the odin code in the package
odin::odin_package(pkg)

# Which creates the rest of the package structure
dir(pkg)
#> [1] "DESCRIPTION" "NAMESPACE"   "R"           "inst"        "src"        
dir(file.path(pkg, "R"))
#> [1] "odin.R"
dir(file.path(pkg, "src"))
#> [1] "odin.c"         "registration.c"