Rcpp関数内でファイルを開こうとしているので、ファイル名を char* または std::string にする必要があります。
これまでのところ、次のことを試しました。
#include <Rcpp.h>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <string>
RcppExport SEXP readData(SEXP f1) {
Rcpp::CharacterVector ff(f1);
std::string fname = Rcpp::as(ff);
std::ifstream fi;
fi.open(fname.c_str(),std::ios::in);
std::string line;
fi >> line;
Rcpp::CharacterVector rline = Rcpp::wrap(line);
return rline;
}
しかし、コンパイル時にエラーが発生するas
ため、明らかに機能しません。Rcpp::CharacterVector
foo.cpp: In function 'SEXPREC* readData(SEXPREC*)':
foo.cpp:8: error: no matching function for call to 'as(Rcpp::CharacterVector&)'
make: *** [foo.o] Error 1
引数から文字列を取得する簡単な方法や、Rcpp 関数の引数からファイルを開く簡単な方法はありますか?