Initially, I was importing some data from R directly into a C++ function like so:
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::depends(RcppArmadillo)]]
List gibbs(List dat) {
int N = dat["N"];
arma::vec y = dat["y"];
...
}
Eventually, I needed more than just N and y (the input_data list has many separate vectors and matrices I need to import). So, I thought it would be a good idea to create a class Data to store all the input variables and automatically do some pre-processing in the constructor. Something like
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::depends(RcppArmadillo)]]
class Data {
public:
int N;
arma::vec y;
// other data
Data(List input_data) {
N = input_data["N"];
y = input_data["y"];
// pre-processing steps
}
};
However, this doesn't work. It gives the following error:
object_LocLev.cpp:12:7: error: use of overloaded operator '=' is ambiguous (with operand types 'arma::vec' (aka 'Col<double>') and 'Rcpp::Vector<19>::NameProxy' (aka 'generic_name_proxy<19>'))
y = input_data["y"];
~ ^ ~~~~~~~~~~~~~~~
My question is why does this error appear? Is there a better way of assigning y?