kthohr / mcmc

A C++ library of Markov Chain Monte Carlo (MCMC) methods
https://mcmclib.readthedocs.io/en/latest/
Apache License 2.0
166 stars 45 forks source link

Add mcmc to R package #11

Closed skiptoniam closed 8 months ago

skiptoniam commented 8 months ago

Hi,

I've been trying to follow your instructions for adding mcmc to an R package to use the samplers you've written. I already have a package that uses Eigen and CppAD to generate loglikes and gradients. I can't get mcmc to play with that package.

So to see where I was going wrong I'vee tried starting a new package, that just uses Rcpp, I followed your instructions of using the header only version and adding the following at the stop of my cpp file: #define MCMC_USE_RCPP_EIGEN #include "mcmc.hpp" When I try to build a it I get the following error: #error MCMClib: you must enable the armadillo or eigen wrappers

When I add #define MCMC_ENABLE_EIGEN_WRAPPERS I get the following error: #error Eigen must be version 3.4.0 or above

Anyway, any help would be greatly appreciated as I'm very keen to use your samplers, rather than having to write them out myself.

Kind regards,

Skip.

kthohr commented 8 months ago

The error arises because RcppEigen has not updated the base version of Eigen for a few years now (though not due to laziness on Dirk's part, rather the package maintainers ran into issues when doing so), and the latest version of my library requires Eigen >= v3.4.0. I'll update my documentation to remove RcppEigen as an option.

skiptoniam commented 8 months ago

Any clues on how to set it up in R without RcppEigen?

skiptoniam commented 8 months ago

For anyone playing along, I downloaded https://gitlab.com/libeigen/eigen/-/releases/3.4.0 and added the Eigen folder to inst/include/ in my R package and then used: #define MCMC_ENABLE_EIGEN_WRAPPERS #include "mcmc.hpp" To include the mcmc code

My makevars file has the following: PKG_CPPFLAGS = -I../inst/include/ to point to these headers