私はRcpp関数内でファイルを開くしようとしていますので、私がchar *またはSTDとしてファイル名を必要とする::文字列。Rcppを変換する:: CharacterVector先はstd ::文字列
はこれまでのところ、私は次のことを試してみました:
#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関数の引数からファイルを開く方法はありますか?
はRcpp ::(FF)として動作しますか? –
@IanFellows、うん、それは動作します! – highBandWidth