[Rd] Using a C++ library to read a binary file

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed May 25 10:16:48 CEST 2005

Demitri Muna wrote:

> Hello,
> I am trying to use a C++ library I have to read some data into R.  I've 
> gone over the "Writing R Extensions" page and some of the  archives, but 
> am left somewhat confused (and I'm still very new to R!).
> What I want to do is fairly simple. Given some parameters, I'd like  to 
> read a string of numbers from a proprietary binary file into an  array. 
> I have a C++ library that will read anything I need from this  file.
> What is the best way to do this? Can someone give me any pointers to  
> sample code?

You might be able to write a C wrapper around your C++ code and link 
that into R, so R can get the data directly from a .C() call to your 
wrapper function. See Writing R Extensions for details.

> One possibility I've considered is writing a small unix command line  
> program that, given the parameters, will return the string of  numbers. 
> Is there a way to "capture" this from R into an array?

Yes, this way will also work, please read the R Data Import/Export 
manual and ?connection.

Uwe Ligges

> Cheers,
> Demitri
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list