Using RcppEnsmallen in Your Own R Package

James Joseph Balamuta


This vignette describes the best practices for using RcppEnsmallen in your own R package.


RcppEnsmallen is best used within an R package. The setup for RcppEnsmallen’s use mirrors that of other Rcpp-based projects. In particular, the DESCRIPTION file requires the LinkingTo field and two files inside the src/ to establish the necessary compilation options. In the next two sections, we show the modifications.


Open your R package’s DESCRIPTION file. Ensure that the LinkingTo directive is present and contains:

LinkingTo: Rcpp, RcppArmadillo (>= 0.9.800.0.0), RcppEnsmallen (>=

Makevars inside the src/ Directory

Next, the src/ directory must contain both a Makevars and file. Each file must have the same contents of:


The file provides the appropriate configuration for Windows while Makevars acts on Unix-alike systems like macOS, Linux, and Solaris.