Like most users I have no idea what I’m doing to get this stuff to work and I’m just cutting and pasting stuff found on the internet. I was able to get this working with the following. Not sure if the gfortran stuff is needed.
Hopefully this helps anyone else.
Notes to get working:
- Updated Rstudio (2021.09.1 Build 372) and R (4.1.2)
- Installed Xcode
- Login to https://developer.apple.com/download/all
- Download and install Command Line Tools for Xcode 13.x (click on dmg)
Also did this
- Went to https://github.com/fxcoudert/gfortran-for-macOS/releases
- Download and install https://github.com/fxcoudert/gfortran-for-macOS/releases/download/11.2-monterey-intel/gfortran-Intel-11.2-Monterey.dmg
Tested cpp in R via
install.packages(c("remotes", "Rcpp", "RcppArmadillo")
Saved this helloworld.cpp
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
void hello_world() {
Rcpp::Rcout << "Hello World!" << std::endl;
}
// After compile, this function will be immediately called using
// the below snippet and results will be sent to the R console.
/*** R
hello_world()
*/
Back in R test
Rcpp::sourceCpp('path/to/file/helloworld.cpp')
That showed hello_world()
so I was good.
Then I followed rstan
updated install at https://github.com/stan-dev/rstan/pull/887