I am working through the book \"Seamless R and C++ Integration with Rcpp\". I am using R version 3.1.0 on Ubuntu 12.04. I cannot figure out how to properly link the necess
Can you run the following command, please:
edd@max:~$ dpkg -l | grep libgfortran | cut -c-75
ii libgfortran-4.7-dev:amd64 4.7.3-7ubuntu3
ii libgfortran-4.8-dev:amd64 4.8.1-10ubuntu9
ii libgfortran3:amd64 4.8.1-10ubuntu9
edd@max:~$
You need the libgfortrain-$VERSION-dev
package for your machine. At some point having gfortran
implied this via r-base-dev
and its dependence on build-essentials
.
Edit: Version numbers will of course be different on your 12.04 release; this was from a machine running 13.10.
Edit 2, based on your update: Your use of sourceCpp()
is incorrect. You are not telling Rcpp that you need Armadillo, so Rcpp responds by saying it does not know Armadillo. You can either use a Rcpp::depends()
in the cpp file, or use the plugin=
argument.
So here is how I would write the code you have above. You can then just call sourceCpp()
on the file which will create a function rcppSim()
you can call:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::mat rcppSim(arma::mat coeff, arma::mat errors) {
int m = errors.n_rows;
int n = errors.n_cols;
arma::mat simdata(m,n);
simdata.row(0) = arma::zeros<arma::mat>(1, n);
for (int row=1; row < m; row++) {
simdata.row(row) = simdata.row(row-1)*trans(coeff) + errors.row(row);
}
return simdata;
}