Question

J'essaie d'ouvrir un fichier dans un RCPP Fonction, j'ai donc besoin du nom de fichier en tant que chaîne char * ou std ::.

Jusqu'à présent, j'ai essayé ce qui suit:

#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;
}

Mais apparemment, as ne fonctionne pas pour Rcpp::CharacterVector Comme j'obtiens une erreur de compilation.

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

Existe-t-il un moyen simple d'obtenir une chaîne à partir de l'argument ou d'ouvrir en quelque sorte un fichier à partir de l'argument de la fonction RCPP?

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top