• Coding Hacks

    A really smart former collaborator keeps some coding hacks on his webpage. An idea worth stealing!

    Building an R package containing RcppArmadillo source code

    It took me forever to figure out how to successfully build my code with calls to the optimized matrix math library, RcppArmadillo, into an R package. Now I'll just remember to look here.

    - setwd() to the directory where you want to make your package

    - library(RcppArmadillo)

    - RcppArmadillo.package.skeleton(name = "mypackage")

    - put Rcpp code with RcppArmadillo calls into /src/

    - Use GUI Rstudio utility to "create new package", selecting a preexisting directory for package

    - then open the new mypackage.Rproj file

    - devtools::document()

    - add a .R file containing

    #' @useDynLib mypackage

    #' @importFrom Rcpp sourceCpp


    - then hit Build & Reload, and use your package!