I have recently started experimenting with interfacing C++ with R and I am struggling with the following C++ function. Specifically I am trying to use sourceCpp with the following .cpp file
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include <algorithm>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::unordered_map<std::string,std::string> example_function(std::unordered_map<std::string,std::vector<std::string>> map_1, std::unordered_map<std::string,std::vector<std::string>> map_2)
{
std::unordered_map<std::string, std::string> example_map;
//Do some things to example_map and return it
return example_map;
}
The error I am getting is on some line of Exporter.h and it states
no matching function for call to 'std::unordered_map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > >::unordered_map(SEXPREC*&)
invalid conversion from 'SEXP' {aka 'SEXPREC*'} to 'std::unordered_map<std::__cxx11::basic_string<char>, std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-fpermissive]
My understanding of the issue is that C++ has no way to "translate" unordered_map<std::string, std::vector <std::string> >
into R. I understand that I need to write to functions for this, one that turns C++ into R, and one that turns R into C++ but I do not know where to start. I would be grateful for your help.
Thanks in advance.