[Rcpp-devel] Need some hep reading files
Sokol Serguei
serguei.sokol at gmail.com
Wed Aug 3 11:14:41 CEST 2022
Le 29/07/2022 à 23:43, Roberto Spadim a écrit :
> I don't know if I'm clear in last message
> What I want to do is something like this, but i don't know if Rcpp can
> 'convert' the ifstream to SEXP and keep the object intact:
XPtr was designed to wrap any C++ pointer to SEXP structure and make a
backward conversion too. So I would start with this kind of helper.
For example, see
https://www.r-bloggers.com/2010/01/external-pointers-with-rcpp/
You have to pay a particular attention to what should happen if on R
side, your pointer-wrapper goes out of scope and thus becomes a subject
to garbage collection. Should your ifstream be destroyed automatically
at this moment or you will do it later by yourself?
Best,
Serguei.
>
> One RCPP function to open the file and return the "ifstream" object
>
> ifstream some_open_function(){
> ifstream infile;
> infile.open("afile.dat");
> return infile;
> }
>
> one read function:
>
> string read_file(ifstream infile){
> string data;
> infile >> data;
> return data;
> }
>
> one close function:
>
> void close_file(ifstream infile){
> infile.close();
> }
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
More information about the Rcpp-devel
mailing list